Skip to content

Commit 2353278

Browse files
committed
[test] format test script, addpath in ci script
1 parent e28ed9c commit 2353278

2 files changed

Lines changed: 30 additions & 23 deletions

File tree

test/run_redbird_test.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ function run_redbird_test(tests)
3737
tests = {'util', 'jac', 'prop', 'mesh', 'forward', 'solver', 'recon'};
3838
end
3939

40-
global RB_FAIL RB_TOTAL;
40+
global RB_FAIL RB_TOTAL
4141
RB_FAIL = 0;
4242
RB_TOTAL = 0;
4343

4444
if (~exist('rbrun', 'file'))
45-
addpath(fullfile(fileparts(mfilename('fullpath')), '..', 'matlab'));
45+
addpath([fileparts(which(mfilename)) filesep '..' filesep 'matlab']);
4646
end
47-
addpath(fileparts(mfilename('fullpath')));
4847

4948
bar = char(ones(1, 79) * 61);
5049

test/test_redbird.m

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@
2222
% -- this function is part of Redbird-m toolbox
2323
%
2424

25-
global RB_RTOL RB_ATOL RB_FAIL RB_TOTAL;
26-
if isempty(RB_RTOL); RB_RTOL = 1e-9; end
27-
if isempty(RB_ATOL); RB_ATOL = 1e-12; end
28-
if isempty(RB_FAIL); RB_FAIL = 0; end
29-
if isempty(RB_TOTAL); RB_TOTAL = 0; end
25+
global RB_RTOL RB_ATOL RB_FAIL RB_TOTAL
26+
if isempty(RB_RTOL)
27+
RB_RTOL = 1e-9;
28+
end
29+
if isempty(RB_ATOL)
30+
RB_ATOL = 1e-12;
31+
end
32+
if isempty(RB_FAIL)
33+
RB_FAIL = 0;
34+
end
35+
if isempty(RB_TOTAL)
36+
RB_TOTAL = 0;
37+
end
3038

3139
RB_TOTAL = RB_TOTAL + 1;
3240

@@ -39,15 +47,15 @@
3947
end
4048
pass = threw;
4149
report(testname, pass, 'expected an error');
42-
return;
50+
return
4351
end
4452

4553
try
4654
if (ischar(expected) && strcmp(expected, 'noerror'))
4755
fhandle(varargin{:});
4856
pass = true;
4957
report(testname, pass, 'no error');
50-
return;
58+
return
5159
end
5260
out = fhandle(varargin{:});
5361
[pass, msg] = compare(out, expected, RB_RTOL, RB_ATOL);
@@ -69,19 +77,19 @@
6977
catch err
7078
why = sprintf('predicate threw: %s', err.message);
7179
end
72-
return;
80+
return
7381
end
7482
if isnumeric(expected) || islogical(expected)
7583
if ~isequal(size(actual), size(expected))
7684
why = sprintf('size mismatch: got [%s], expected [%s]', ...
7785
sprintf('%d ', size(actual)), sprintf('%d ', size(expected)));
78-
return;
86+
return
7987
end
8088
a = double(actual(:));
8189
e = double(expected(:));
8290
if any(isnan(a) ~= isnan(e))
8391
why = 'NaN pattern mismatch';
84-
return;
92+
return
8593
end
8694
a(isnan(a)) = 0;
8795
e(isnan(e)) = 0;
@@ -94,54 +102,54 @@
94102
why = sprintf('numerical mismatch at idx %d: |%g-%g|=%g > %g', ...
95103
bad, a(bad), e(bad), diff(bad), tol(max(numel(tol), 1)));
96104
end
97-
return;
105+
return
98106
end
99107
if ischar(expected)
100108
ok = ischar(actual) && strcmp(actual, expected);
101109
if ~ok
102110
why = 'string mismatch';
103111
end
104-
return;
112+
return
105113
end
106114
if iscell(expected)
107115
if ~iscell(actual) || ~isequal(size(actual), size(expected))
108116
why = 'cell shape mismatch';
109-
return;
117+
return
110118
end
111119
for k = 1:numel(expected)
112120
[ok2, why2] = compare(actual{k}, expected{k}, rtol, atol);
113121
if ~ok2
114122
why = sprintf('cell{%d}: %s', k, why2);
115-
return;
123+
return
116124
end
117125
end
118126
ok = true;
119-
return;
127+
return
120128
end
121129
if isstruct(expected)
122130
if ~isstruct(actual)
123131
why = 'expected struct';
124-
return;
132+
return
125133
end
126134
fn = fieldnames(expected);
127135
for k = 1:numel(fn)
128136
if ~isfield(actual, fn{k})
129137
why = sprintf('missing field %s', fn{k});
130-
return;
138+
return
131139
end
132140
[ok2, why2] = compare(actual.(fn{k}), expected.(fn{k}), rtol, atol);
133141
if ~ok2
134142
why = sprintf('field %s: %s', fn{k}, why2);
135-
return;
143+
return
136144
end
137145
end
138146
ok = true;
139-
return;
147+
return
140148
end
141149
why = sprintf('unsupported expected type %s', class(expected));
142150

143151
function report(testname, pass, msg)
144-
global RB_FAIL;
152+
global RB_FAIL
145153
if pass
146154
fprintf(1, 'Testing %s: ok\n', testname);
147155
else

0 commit comments

Comments
 (0)