Skip to content

Commit 2c58aee

Browse files
committed
Update system model unit tests
1 parent a74345a commit 2c58aee

File tree

87 files changed

+324
-1516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+324
-1516
lines changed

Components/HEVPowerSplitControl/HEVPowerSplitControl_params.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
% These are for controller/driver only.
5555
% ICs for plant are defined elsewhere.
5656

57-
initial.driverHVBattSOC_pct = initial.highVoltageBatterySOC_pct;
57+
initial.controllerHVBattSOC_pct = initial.highVoltageBatterySOC_pct;
5858

5959
initial.driverBrakeForce_N = 8000;
6060
initial.driverBrakeOn_tf = true;
Binary file not shown.
Binary file not shown.

HEV/PowerSplitHEV_DirectInput/test/PowerSplitHEV_DirectInput_UnitTest.m

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,45 @@
77
modelName = "PowerSplitHEV_system_model";
88
end
99

10-
methods (Test)
10+
methods (TestClassSetup)
11+
%% Functions to be executed when this unit test class is instanciated.
1112

12-
function defaultReferencedSubsystems_1(testCase)
13-
%% Test for Default Referenced Subsystems
14-
% This ensures that all the subsystem reference blocks in the model file have
15-
% intended referenced subsystems.
16-
close all
17-
bdclose all
13+
function setReferencedSubsystems(testCase)
14+
%% Set referenced subsystems for this unit test.
15+
% Note that other referenced subsystems may also be used in some tests.
16+
17+
disp("Running a function from TestClassSetup...")
18+
19+
% Teardown sets a function to be executed when the class object is destroyed.
20+
% In this case, recover the "global default" referenced subsystems.
21+
addTeardown(testCase, @PowerSplitHEV_resetReferencedSubsystems, testCase.modelName)
1822

1923
mdl = testCase.modelName;
2024
load_system(mdl)
2125

22-
refSubName = get_param(mdl+"/Controller & Environment", "ReferencedSubsystem");
23-
verifyEqual(testCase, refSubName, 'PowerSplitHEV_DirectInput_refsub');
26+
set_param( mdl + "/Controller & Environment", ...
27+
"ReferencedSubsystem", "PowerSplitHEV_DirectInput_refsub");
2428

25-
refSubName = get_param(mdl+"/High Voltage Battery", "ReferencedSubsystem");
26-
verifyEqual(testCase, refSubName, 'BatteryHVElec_refsub');
29+
set_param( mdl + "/High Voltage Battery", ...
30+
"ReferencedSubsystem", "BatteryHVElec_refsub");
2731

28-
refSubName = get_param(mdl+"/DC-DC Converter", "ReferencedSubsystem");
29-
verifyEqual(testCase, refSubName, 'DcDcConverterElec_refsub');
32+
set_param( mdl + "/DC-DC Converter", ...
33+
"ReferencedSubsystem", "DcDcConverterElec_refsub");
3034

31-
refSubName = get_param(mdl+"/Power Split Drive Unit", "ReferencedSubsystem");
32-
verifyEqual(testCase, refSubName, 'PowerSplitDriveUnitBasic_refsub');
35+
set_param( mdl + "/Power Split Drive Unit", ...
36+
"ReferencedSubsystem", "PowerSplitDriveUnitBasic_refsub");
3337

34-
refSubName = get_param(mdl+"/Longitudinal Vehicle", "ReferencedSubsystem");
35-
verifyEqual(testCase, refSubName, 'Vehicle1DCustom_refsub');
38+
set_param( mdl + "/Longitudinal Vehicle", ...
39+
"ReferencedSubsystem", "Vehicle1DCustom_refsub");
3640

37-
close all
38-
bdclose all
39-
end
41+
save_system(mdl)
42+
43+
end % function
44+
45+
end % methods (TestClassSetup)
46+
47+
methods (Test)
48+
%% Test for Models
4049

4150
function openAndRun_1(testCase)
4251
%% Most basic check - open model and run simulation.
@@ -61,7 +70,7 @@ function openAndRun_1(testCase)
6170

6271
function openAndRun_2_1(testCase)
6372
%% Check that the model runs without any warnings or errors.
64-
% Specify the referenced subsystems.
73+
% Test referenced subsystems that are different from this unit test's default.
6574

6675
close all
6776
bdclose all
@@ -91,7 +100,7 @@ function openAndRun_2_1(testCase)
91100

92101
function openAndRun_2_2(testCase)
93102
%% Check that the model runs without any warnings or errors.
94-
% Specify the referenced subsystem.
103+
% Test referenced subsystems that are different from this unit test's default.
95104

96105
close all
97106
bdclose all
@@ -135,14 +144,6 @@ function runLiveScript_DirectInput_Constant(~)
135144
bdclose all
136145
end
137146

138-
function runLiveScript_DirectInput_Accel(~)
139-
close all
140-
bdclose all
141-
PowerSplitHEV_DI_testcase_Accel
142-
close all
143-
bdclose all
144-
end
145-
146147
function runLiveScript_DirectInput_Downhill(~)
147148
close all
148149
bdclose all
@@ -191,15 +192,13 @@ function runLiveScript_DirectInput_PowerSplitDrive(~)
191192
bdclose all
192193
end
193194

194-
%{
195195
function runLiveScript_main_script(~)
196196
close all
197197
bdclose all
198198
PowerSplitHEV_DirectInput_main_script
199199
close all
200200
bdclose all
201201
end
202-
%}
203202

204203
end % methods (Test)
205204
end % classdef

HEV/PowerSplitHEV_DirectInput/test/PowerSplitHEV_DirectInput_runtests.m

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
PrjRoot = currentProject().RootFolder;
1313

14-
TopFolder = fullfile(PrjRoot, "HEV", "PowerSplitHEV");
14+
TopFolder = fullfile(PrjRoot, "HEV", ComponentName);
1515
assert(isfolder(TopFolder))
1616

1717
UnitTestFolder = fullfile(TopFolder, "test");
@@ -20,13 +20,10 @@
2020
UnitTestFile = fullfile(UnitTestFolder, ComponentName+"_UnitTest.m");
2121
assert(isfile(UnitTestFile))
2222

23-
TestCaseFolder = fullfile(TopFolder, "testcases_DirectInput");
23+
TestCaseFolder = fullfile(TopFolder, "testcases");
2424
assert(isfolder(TestCaseFolder))
2525

26-
UtilsFolder = fullfile(TopFolder, "utils_Common");
27-
assert(isfolder(UtilsFolder))
28-
29-
UtilsFolder = fullfile(TopFolder, "utils_DirectInput");
26+
UtilsFolder = fullfile(TopFolder, "utils");
3027
assert(isfolder(UtilsFolder))
3128

3229
%%
@@ -61,22 +58,17 @@
6158

6259
plugin = matlab.unittest.plugins.CodeCoveragePlugin.forFile( ...
6360
[ fullfile(TopFolder, "test", ComponentName+"_UnitTest.m"), ...
64-
fullfile(TopFolder, "testcases_DirectInput", "PowerSplitHEV_DI_testcase_Accel.mlx"), ...
65-
fullfile(TopFolder, "testcases_DirectInput", "PowerSplitHEV_DI_testcase_Constant.mlx"), ...
66-
fullfile(TopFolder, "testcases_DirectInput", "PowerSplitHEV_DI_testcase_Downhill.mlx"), ...
67-
fullfile(TopFolder, "testcases_DirectInput", "PowerSplitHEV_DI_testcase_Downhill_2.mlx"), ...
68-
fullfile(TopFolder, "testcases_DirectInput", "PowerSplitHEV_DI_testcase_MG1Drive.mlx"), ...
69-
fullfile(TopFolder, "testcases_DirectInput", "PowerSplitHEV_DI_testcase_MG2Drive.mlx"), ...
70-
fullfile(TopFolder, "testcases_DirectInput", "PowerSplitHEV_DI_testcase_MG2Drive_2.mlx"), ...
71-
fullfile(TopFolder, "testcases_DirectInput", "PowerSplitHEV_DI_testcase_PowerSplitDrive.mlx"), ...
72-
fullfile(TopFolder, "utils_Common", "PowerSplitHEV_plot_result_compact.m"), ...
73-
fullfile(TopFolder, "utils_Common", "PowerSplitHEV_plot_result_hvbattery.m"), ...
74-
fullfile(TopFolder, "utils_Common", "PowerSplitHEV_plot_result_powersplit.m"), ...
75-
fullfile(TopFolder, "utils_Common", "PowerSplitHEV_plot_result_vehicle.m"), ...
76-
fullfile(TopFolder, "utils_DirectInput", "PowerSplitHEV_DirectInput_InputSignalBuilder.m"), ...
77-
fullfile(TopFolder, "utils_DirectInput", "PowerSplitHEV_DirectInput_setup.m"), ...
78-
fullfile(TopFolder, "PowerSplitHEV_DirectInput_main_script.mlx"), ...
79-
fullfile(TopFolder, "PowerSplitHEV_params.m") ], ...
61+
fullfile(TopFolder, "testcases", "PowerSplitHEV_DI_testcase_Constant.mlx"), ...
62+
fullfile(TopFolder, "testcases", "PowerSplitHEV_DI_testcase_Downhill.mlx"), ...
63+
fullfile(TopFolder, "testcases", "PowerSplitHEV_DI_testcase_Downhill_2.mlx"), ...
64+
fullfile(TopFolder, "testcases", "PowerSplitHEV_DI_testcase_MG1Drive.mlx"), ...
65+
fullfile(TopFolder, "testcases", "PowerSplitHEV_DI_testcase_MG2Drive.mlx"), ...
66+
fullfile(TopFolder, "testcases", "PowerSplitHEV_DI_testcase_MG2Drive_2.mlx"), ...
67+
fullfile(TopFolder, "testcases", "PowerSplitHEV_DI_testcase_PowerSplitDrive.mlx"), ...
68+
fullfile(TopFolder, "utils", "PowerSplitHEV_DirectInput_example.m"), ...
69+
fullfile(TopFolder, "utils", "PowerSplitHEV_DirectInput_InputSignalBuilder.m"), ...
70+
fullfile(TopFolder, "utils", "PowerSplitHEV_DirectInput_selectInput.m"), ...
71+
fullfile(TopFolder, "PowerSplitHEV_DirectInput_main_script.mlx") ], ...
8072
Producing = coverageReport );
8173

8274
addPlugin(runner, plugin)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)