Skip to content

Commit 4f1ccdc

Browse files
authored
Improve Reducer component resources. Add more tests. Add custom rules for the Code Analyzer. (#43)
1 parent 441ca41 commit 4f1ccdc

File tree

421 files changed

+25808
-9121
lines changed

Some content is hidden

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

421 files changed

+25808
-9121
lines changed

BEV/BEV_system_model.mdl

Lines changed: 12 additions & 11 deletions
Large diffs are not rendered by default.

BEV/Model-Basic/SimulationCases/buildfile.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function plan = buildfile
2-
%% Define tasks for buildtool to check code and run tests
3-
% In the Editor, use Run Build button to start task.
2+
% Define tasks for the buildtool to check code and run tests.
3+
% In the Editor, use the "Run Build" button to start a task.
44

55
% Overview of MATLAB Build Tool
66
% https://www.mathworks.com/help/matlab/matlab_prog/overview-of-matlab-build-tool.html

BEV/Model-Thermal/SimulationCases/buildfile.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function plan = buildfile
2-
%% Define tasks for buildtool to check code and run tests
3-
% In the Editor, use Run Build button to start task.
2+
% Define tasks for the buildtool to check code and run tests.
3+
% In the Editor, use the "Run Build" button to start a task.
44

55
% Overview of MATLAB Build Tool
66
% https://www.mathworks.com/help/matlab/matlab_prog/overview-of-matlab-build-tool.html

BEV/buildfile.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function plan = buildfile
2-
%% Define tasks for buildtool to check code and run tests
3-
% In the Editor, use Run Build button to start task.
2+
% Define tasks for the buildtool to check code and run tests.
3+
% In the Editor, use the "Run Build" button to start a task.
44

55
% Overview of MATLAB Build Tool
66
% https://www.mathworks.com/help/matlab/matlab_prog/overview-of-matlab-build-tool.html
207 Bytes
Loading
0 Bytes
Loading

BEV/unittest_BEV.m

Lines changed: 0 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -51,153 +51,6 @@ function PassingTest_4(~)
5151
evalin("base", "BEV_main_script");
5252
end % function
5353

54-
%% Link tests
55-
56-
function LinkTest_1(testcase)
57-
% Check all the Callback Button blocks in a model.
58-
% Different tests are done depending on the name of the block.
59-
% - "Plot ..." makes a visualization/plot using some block parameters.
60-
% - "Open ... app" opens an app.
61-
% - "Open ... script" opens the script in the Editor.
62-
% - Something else, which is assumed to be in a script call style, not in a function call style.
63-
%
64-
% Get the ClickFcn property of the Callback Button block and validate it.
65-
% ClickFcn should call one main action, optionally with the disp command, comment lines, or empty lines.
66-
67-
model_name = "BEV_system_model";
68-
69-
load_system(model_name)
70-
71-
block_paths = string(getfullname(Simulink.findBlocksOfType(model_name, "CustomCallbackButton")));
72-
73-
num_blocks = numel(block_paths);
74-
for idx = 1 : num_blocks
75-
target_block_path = block_paths(idx);
76-
77-
disp("Found a Custom Callback Button: " + target_block_path)
78-
79-
[system_path, block_name, ~] = fileparts(target_block_path);
80-
81-
find_options = Simulink.FindOptions(SearchDepth = 1);
82-
all_found_blocks = string(getfullname(Simulink.findBlocks(system_path, find_options)));
83-
84-
ClickFcn_text = string(get_param(target_block_path, "ClickFcn"));
85-
86-
lines = splitlines(ClickFcn_text);
87-
88-
if height(lines) > 1
89-
% Remove comment lines.
90-
logical_index = not(startsWith(lines, "%"));
91-
lines = lines(logical_index);
92-
93-
% Remove empty lines.
94-
logical_index = not(lines == "");
95-
lines = lines(logical_index);
96-
97-
% Remove lines containing the disp command.
98-
% This assumes that the target text is not in the same line as disp.
99-
logical_index = not(contains(lines, "disp("));
100-
lines = lines(logical_index);
101-
end % if
102-
103-
if height(lines) > 1
104-
% Skip testing if there are 2 or more lines remaining at this point.
105-
% !todo: Test the callback code even when it has 2 or more lines.
106-
107-
continue
108-
109-
end % if
110-
111-
target_line = lines;
112-
disp("Target: " + target_line)
113-
114-
if startsWith(block_name, "Plot")
115-
% Plot button.
116-
%
117-
% The text lines must be in the following style.
118-
% plotFunction(gcs + "/Target block")
119-
%
120-
% Check the plotFunction and the target block.
121-
122-
% Use which to get the full path to the plot function.
123-
target_function_name = extractBefore(target_line, "(");
124-
disp("Plot: " + target_function_name)
125-
target_function_fullpath = string(which(target_function_name)); % !test-target
126-
verifyTrue(testcase, target_function_fullpath ~= "")
127-
128-
% Get
129-
% /Target block
130-
% from
131-
% (gcs + "/Target block", ...)
132-
sp = optionalPattern(whitespacePattern);
133-
extracted_block_name = extractBetween(target_line, "("+sp+"gcs"+sp+"+"+sp+"""", """"+optionalPattern(sp+","+wildcardPattern("Except",""""))+sp+")");
134-
% Construct a full block path and check it.
135-
constructed_block_path = system_path + extracted_block_name;
136-
logical_index = constructed_block_path == all_found_blocks; % !test-target
137-
verifyEqual(testcase, nnz(logical_index), 1)
138-
139-
elseif startsWith(block_name, "Open") && endsWith(block_name, whitespacePattern+("A"|"a")+"pp")
140-
% App button.
141-
%
142-
% The text lines must be in the following style.
143-
% SomeApp
144-
% or
145-
% SomeApp(gcs + "/Target block")
146-
%
147-
% Check the SomeApp and the target block.
148-
% - The app name must end with "App".
149-
150-
verifyTrue(testcase, contains(target_line, "App" + alphanumericBoundary))
151-
152-
if contains(target_line, "App(")
153-
target_app_name = extractBefore(target_line, "(");
154-
else
155-
target_app_name = target_line;
156-
end % if
157-
disp("App: " + target_app_name)
158-
159-
% Use which to get the full path to the plot function.
160-
target_app_fullpath = string(which(target_app_name)); % !test-target
161-
verifyTrue(testcase, target_app_fullpath ~= "")
162-
163-
if contains(target_line, "App(")
164-
% Get
165-
% /Target block
166-
% from
167-
% (gcs + "/Target block", ...)
168-
sp = optionalPattern(whitespacePattern);
169-
extracted_block_name = extractBetween(target_line, "("+sp+"gcs"+sp+"+"+sp+"""", """"+optionalPattern(sp+","+wildcardPattern("Except",""""))+sp+")");
170-
% Construct a full block path and check it.
171-
constructed_block_path = system_path + extracted_block_name;
172-
logical_index = constructed_block_path == all_found_blocks; % !test-target
173-
verifyEqual(testcase, nnz(logical_index), 1)
174-
end % if
175-
176-
elseif startsWith(block_name, "Open") && endsWith(block_name, whitespacePattern+("S"|"s")+"cript")
177-
% Open a script in the Editor.
178-
% edit("script_name")
179-
%
180-
% Check that the script_name exists.
181-
182-
verifyTrue(testcase, startsWith(target_line, "edit("))
183-
184-
sp = optionalPattern(whitespacePattern);
185-
script_name = extractBetween(target_line, "("+sp+"""", """"+sp+")");
186-
disp("Script: " + script_name)
187-
188-
target_fullpath = string(which(script_name)); % !test-target
189-
verifyTrue(testcase, target_fullpath ~= "")
190-
191-
else
192-
disp("Not plot, not app, not edit.")
193-
% Assume that the target text is in a script style, not a function style.
194-
target_fullpath = string(which(target_line)); % !test-target
195-
verifyTrue(testcase, target_fullpath ~= "")
196-
197-
end % if
198-
end % for
199-
end % function
200-
20154
end % methods
20255

20356
end % classdef

0 commit comments

Comments
 (0)