Skip to content

Commit 0c2c581

Browse files
committed
Revamp Drive Pattern component
1 parent 035869f commit 0c2c581

File tree

101 files changed

+1635
-148
lines changed

Some content is hidden

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

101 files changed

+1635
-148
lines changed
148 KB
Binary file not shown.
163 KB
Binary file not shown.
85.1 KB
Binary file not shown.
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
classdef DrivePattern_UnitTest < matlab.unittest.TestCase
2+
% Class implementation of unit test
3+
4+
% Copyright 2021-2022 The MathWorks, Inc.
5+
6+
properties (Constant)
7+
modelName = "DrivePattern_harness_model";
8+
end
9+
10+
methods (Test)
11+
12+
function run_harness_model_1(testCase)
13+
%% The most basic test - just open the model and run simulation.
14+
% Check that the model runs without any warnings or errors.
15+
16+
close all
17+
bdclose all
18+
19+
mdl = testCase.modelName;
20+
21+
t_end = 10; % Simulation stop time in seconds
22+
23+
load_system(mdl)
24+
25+
simIn = Simulink.SimulationInput(mdl);
26+
simIn = setModelParameter(simIn, "StopTime",num2str(t_end));
27+
28+
sim(simIn);
29+
30+
close all
31+
bdclose all
32+
end % function
33+
34+
%% Test for Inputs
35+
% Check that the Input Signal Builder class works.
36+
37+
function input_Constant(~)
38+
% All default
39+
close all
40+
builder = DrivePattern_InputSignalBuilder;
41+
data = Constant(builder);
42+
data.Signals;
43+
data.Bus;
44+
data.Options.StopTime_s;
45+
close all
46+
end % function
47+
48+
function input_Step3(~)
49+
% Make a plot.
50+
close all
51+
builder = DrivePattern_InputSignalBuilder('Plot_tf',true);
52+
data = Step3(builder);
53+
data.Signals;
54+
data.Bus;
55+
data.Options.StopTime_s;
56+
close all
57+
end % function
58+
59+
function input_Step5(~)
60+
% Make a plot.
61+
close all
62+
builder = DrivePattern_InputSignalBuilder('Plot_tf',true);
63+
data = Step5(builder);
64+
data.Signals;
65+
data.Bus;
66+
data.Options.StopTime_s;
67+
close all
68+
end % function
69+
70+
function input_Accelerate_Decelerate(~)
71+
% Make a plot and save it as PNG file.
72+
close all
73+
builder = DrivePattern_InputSignalBuilder('Plot_tf',true);
74+
builder.VisiblePlot_tf = false;
75+
builder.SavePlot_tf = true; % Save
76+
data = Accelerate_Decelerate(builder);
77+
data.Signals;
78+
data.Bus;
79+
data.Options.StopTime_s;
80+
close all
81+
assert(isfile("image_input_signals.png"))
82+
delete("image_input_signals.png")
83+
end % function
84+
85+
function input_Accelerate_Decelerate_Twice(~)
86+
% Make a plot.
87+
close all
88+
builder = DrivePattern_InputSignalBuilder('Plot_tf',true);
89+
data = Accelerate_Decelerate_Twice(builder);
90+
data.Signals;
91+
data.Bus;
92+
data.Options.StopTime_s;
93+
close all
94+
end % function
95+
96+
function input_SimpleDrivePattern(~)
97+
% Make a plot.
98+
close all
99+
builder = DrivePattern_InputSignalBuilder('Plot_tf',true);
100+
data = SimpleDrivePattern(builder);
101+
data.Signals;
102+
data.Bus;
103+
data.Options.StopTime_s;
104+
close all
105+
end % function
106+
107+
function input_FTP75(~)
108+
% Make a plot.
109+
close all
110+
builder = DrivePattern_InputSignalBuilder('Plot_tf',true);
111+
data = FTP75(builder);
112+
data.Signals;
113+
data.Bus;
114+
data.Options.StopTime_s;
115+
close all
116+
end % function
117+
118+
%% Test for Scripts
119+
% Check that scripts run without any warnings or errors.
120+
121+
function run_testcase_1(~)
122+
close all
123+
bdclose all
124+
DrivePattern_testcase_Constant
125+
close all
126+
bdclose all
127+
end
128+
129+
function run_testcase_2(~)
130+
close all
131+
bdclose all
132+
DrivePattern_testcase_Step3
133+
close all
134+
bdclose all
135+
end
136+
137+
function run_testcase_3(~)
138+
close all
139+
bdclose all
140+
DrivePattern_testcase_Step5
141+
close all
142+
bdclose all
143+
end
144+
145+
function run_testcase_4(~)
146+
close all
147+
bdclose all
148+
DrivePattern_testcase_AccelDecel
149+
close all
150+
bdclose all
151+
end
152+
153+
function run_testcase_5(~)
154+
close all
155+
bdclose all
156+
DrivePattern_testcase_AccelDecelTwice
157+
close all
158+
bdclose all
159+
end
160+
161+
function run_testcase_6(~)
162+
close all
163+
bdclose all
164+
DrivePattern_testcase_SimpleDrivePattern
165+
close all
166+
bdclose all
167+
end
168+
169+
function run_testcase_7(~)
170+
close all
171+
bdclose all
172+
DrivePattern_testcase_FTP75
173+
close all
174+
bdclose all
175+
end
176+
177+
function run_main_script_1(~)
178+
close all
179+
bdclose all
180+
DrivePattern_main_script
181+
close all
182+
bdclose all
183+
end
184+
185+
end % methods (Test)
186+
end % classdef
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
%% Run unit tests
2+
% This script runs unit tests and generates a test result summary in XML
3+
% and a MATLAB code coverage report in HTML.
4+
5+
% Copyright 2022 The MathWorks, Inc.
6+
7+
RelStr = matlabRelease().Release;
8+
disp("This is MATLAB " + RelStr)
9+
10+
ComponentName = "DrivePattern";
11+
12+
PrjRoot = currentProject().RootFolder;
13+
14+
TopFolder = fullfile(PrjRoot, "Components", ComponentName);
15+
assert(isfolder(TopFolder))
16+
17+
UnitTestFolder = fullfile(TopFolder, "test");
18+
assert(isfolder(UnitTestFolder))
19+
20+
UnitTestFile = fullfile(UnitTestFolder, ComponentName+"_UnitTest.m");
21+
assert(isfile(UnitTestFile))
22+
23+
suite = matlab.unittest.TestSuite.fromFile( UnitTestFile );
24+
25+
TestCaseFolder = fullfile(TopFolder, "testcases");
26+
assert(isfolder(TestCaseFolder))
27+
28+
% PackageFolder = fullfile(TopFolder, "+"+ComponentName+"Utility");
29+
% assert(isfolder(PackageFolder))
30+
31+
UtilsFolder = fullfile(TopFolder, "utils");
32+
assert(isfolder(UtilsFolder))
33+
34+
runner = matlab.unittest.TestRunner.withTextOutput( ...
35+
OutputDetail = matlab.unittest.Verbosity.Detailed );
36+
37+
%% JUnit Style Test Result
38+
39+
% Test result file is created. There is no need to check its existance.
40+
TestResultFile = "TestResults_" + RelStr + ".xml";
41+
42+
plugin = matlab.unittest.plugins.XMLPlugin.producingJUnitFormat( ...
43+
fullfile(UnitTestFolder, TestResultFile));
44+
45+
addPlugin(runner, plugin)
46+
47+
%% MATLAB Code Coverage Report
48+
49+
CoverageReportFolder = fullfile(TopFolder, "coverage" + RelStr);
50+
if not(isfolder(CoverageReportFolder))
51+
mkdir(CoverageReportFolder)
52+
end
53+
54+
CoverageReportFile = RelStr + "_" + ComponentName + ".html";
55+
56+
coverageReport = matlab.unittest.plugins.codecoverage.CoverageReport( ...
57+
CoverageReportFolder, ...
58+
MainFile = CoverageReportFile );
59+
60+
plugin = matlab.unittest.plugins.CodeCoveragePlugin.forFile( ...
61+
[ fullfile(UnitTestFolder, ComponentName+"_UnitTest.m"), ...
62+
fullfile(TestCaseFolder, ComponentName+"_testcase_AccelDecel.mlx"), ...
63+
fullfile(TestCaseFolder, ComponentName+"_testcase_AccelDecelTwice.mlx"), ...
64+
fullfile(TestCaseFolder, ComponentName+"_testcase_Constant.mlx"), ...
65+
fullfile(TestCaseFolder, ComponentName+"_testcase_FTP75.mlx"), ...
66+
fullfile(TestCaseFolder, ComponentName+"_testcase_SimpleDrivePattern.mlx"), ...
67+
fullfile(TestCaseFolder, ComponentName+"_testcase_Step3.mlx"), ...
68+
fullfile(TestCaseFolder, ComponentName+"_testcase_Step5.mlx"), ...
69+
fullfile(UtilsFolder, ComponentName+"_harness_setup.m"), ...
70+
fullfile(UtilsFolder, ComponentName+"_InputSignalBuilder.m"), ...
71+
fullfile(UtilsFolder, ComponentName+"_plot_inputs.m"), ...
72+
fullfile(UtilsFolder, ComponentName+"_plot_results.m") ], ...
73+
Producing = coverageReport );
74+
75+
addPlugin(runner, plugin)
76+
77+
%%
78+
79+
results = run(runner, suite);
80+
81+
disp(results)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2+
<testsuites>
3+
4+
<testsuite errors="0" failures="0" name="DrivePattern_UnitTest" skipped="0" tests="16" time="66.9901">
5+
<testcase classname="DrivePattern_UnitTest" name="run_harness_model_1" time="9.5734"/>
6+
<testcase classname="DrivePattern_UnitTest" name="input_Constant" time="0.06339"/>
7+
<testcase classname="DrivePattern_UnitTest" name="input_Step3" time="2.0231"/>
8+
<testcase classname="DrivePattern_UnitTest" name="input_Step5" time="0.70542"/>
9+
<testcase classname="DrivePattern_UnitTest" name="input_Accelerate_Decelerate" time="2.8384"/>
10+
<testcase classname="DrivePattern_UnitTest" name="input_Accelerate_Decelerate_Twice" time="0.78692"/>
11+
<testcase classname="DrivePattern_UnitTest" name="input_SimpleDrivePattern" time="0.66513"/>
12+
<testcase classname="DrivePattern_UnitTest" name="input_FTP75" time="0.057499"/>
13+
<testcase classname="DrivePattern_UnitTest" name="run_testcase_1" time="7.3996"/>
14+
<testcase classname="DrivePattern_UnitTest" name="run_testcase_2" time="6.4099"/>
15+
<testcase classname="DrivePattern_UnitTest" name="run_testcase_3" time="6.2886"/>
16+
<testcase classname="DrivePattern_UnitTest" name="run_testcase_4" time="6.1181"/>
17+
<testcase classname="DrivePattern_UnitTest" name="run_testcase_5" time="6.0832"/>
18+
<testcase classname="DrivePattern_UnitTest" name="run_testcase_6" time="6.1043"/>
19+
<testcase classname="DrivePattern_UnitTest" name="run_testcase_7" time="5.3625"/>
20+
<testcase classname="DrivePattern_UnitTest" name="run_main_script_1" time="6.5105"/>
21+
</testsuite>
22+
23+
</testsuites>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)