Skip to content

Commit e034e10

Browse files
author
Cove Sturtevant
committed
Add files via upload
Part 6
1 parent 07ba84e commit e034e10

8 files changed

Lines changed: 1291 additions & 0 deletions

File tree

Lines changed: 375 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,375 @@
1+
function tc = assert_tcase
2+
% assert_tcase -- munit test case to test assert functions.
3+
%
4+
%****f* TestCases/assert_tcase
5+
%
6+
% NAME
7+
% assert_tcase -- munit test case to test assert functions.
8+
%
9+
% USAGE
10+
% run_tcase(@assert_tcase)
11+
%
12+
% INPUTS
13+
% (none)
14+
%
15+
% OUTPUTS
16+
% tc = tcase structure for assert_tcase.
17+
%
18+
% SIDE EFFECTS
19+
%
20+
%
21+
% DESCRIPTION
22+
%
23+
%
24+
25+
% AUTHOR
26+
% Charlie Cornish
27+
%
28+
% CREATION DATE
29+
% 2004-Apr-27
30+
%
31+
% COPYRIGHT
32+
%
33+
%
34+
% CREDITS
35+
%
36+
%
37+
% REVISION
38+
% $Revision: 91 $
39+
%
40+
%***
41+
42+
% $Id: assert_tcase.m 91 2005-03-01 00:37:24Z ccornish $
43+
44+
45+
tc = MU_tcase_new(mfilename);
46+
tc = MU_tcase_add_test(tc, @test_fail);
47+
tc = MU_tcase_add_test(tc, @test_fail_line);
48+
tc = MU_tcase_add_test(tc, @test_assert_isequal_equal);
49+
tc = MU_tcase_add_test(tc, @test_assert_isequal_notequal);
50+
tc = MU_tcase_add_test(tc, @test_assert_isequalwithequalnans_equal_nonans);
51+
tc = MU_tcase_add_test(tc, @test_assert_isequalwithequalnans_equal_withnans);
52+
tc = MU_tcase_add_test(tc, @test_assert_isequalwithequalnans_notequal_nansdiff);
53+
tc = MU_tcase_add_test(tc, @test_assert_fuzzy_diff);
54+
tc = MU_tcase_add_test(tc, @test_assert_numsigdig_diff);
55+
% tc = MU_tcase_add_test(tc, @test_assert_isequalwithequalnans_notequal_nansdiff);
56+
57+
58+
return
59+
60+
function test_fail(varargin)
61+
% Test Description: Test MU_fail function.
62+
% Expected error: AssertionFailedError
63+
expected_msg_id = 'MUNIT:AssertionFailedError';
64+
try
65+
MU_fail('This is a message');
66+
catch
67+
[errmsg, msg_id] = lasterr
68+
69+
if (expected_msg_id == msg_id)
70+
% Passed test
71+
else
72+
% Should not reach here; if so, throw unknow error.
73+
error('MUNIT:UnknownError', ...
74+
'MU_fail did not return expected error');
75+
end
76+
end
77+
return
78+
79+
function test_fail_line(varargin)
80+
% Test Description: Test MU_fail_line function.
81+
% Expected error: AssertionFailedError
82+
expected_msg_id = 'MUNIT:AssertionFailedError';
83+
funcname = mfilename;
84+
linenum = 999;
85+
message = 'This is a test error meesage.';
86+
try
87+
MU_fail_line(funcname, linenum, message);
88+
catch
89+
[errmsg, msg_id] = lasterr;
90+
if (expected_msg_id == msg_id)
91+
% Passed test
92+
else
93+
% Should not reach here; if so, throw unknow error.
94+
error('MUNIT:UnknownError', ...
95+
'MU_fail did not return expected error');
96+
end
97+
end
98+
return
99+
100+
function test_assert_isequal_equal(varargin)
101+
% Test Description: Test MU_assert_isequal function, values are equal.
102+
% Expected result: No error
103+
try
104+
MU_assert_isequal(1, 1);
105+
catch
106+
% Should not reach here; if so, throw unknow error.
107+
error('MUNIT:UnknownError', ...
108+
[mfilename, ' should not reach here.']);
109+
end
110+
return
111+
112+
function test_assert_isequal_notequal(varargin)
113+
% Test Description: Test MU_assert_isequal function, values are not equal.
114+
% Expected result: MUNIT:AssertionFailedError
115+
try
116+
MU_assert_isequal(1, 2);
117+
catch
118+
[errmsg, msg_id] = lasterr;
119+
switch(msg_id)
120+
case 'MUNIT:AssertionFailedError'
121+
% Success -- Expected resutl
122+
otherwise
123+
% Should not reach here; if so, throw unknow error.
124+
error('MUNIT:UnknownError', ...
125+
[mfilename, ' should not reach here.']);
126+
end
127+
end
128+
return
129+
130+
function test_assert_isequalwithequalnans_equal_nonans(varargin)
131+
% Test Description: Test MU_assert_isequalwithequalnans, values are equal.
132+
% Expected result: No error
133+
x = [1:10];
134+
y = [1:10];
135+
try
136+
MU_assert_isequalwithequalnans(x, y);
137+
catch
138+
% Should not reach here; if so, throw unknown error.
139+
error('MUNIT:UnknownError', ...
140+
[mfilename, ' should not reach here.']);
141+
end
142+
return
143+
144+
function test_assert_isequalwithequalnans_equal_withnans(varargin)
145+
% Test Description: Test MU_assert_isequalwithequalnans, values are NaNs.
146+
% Expected result: No error
147+
x = [1:10];
148+
y = [1:10];
149+
x(2) = NaN;
150+
y(2) = NaN;
151+
try
152+
MU_assert_isequalwithequalnans(x, y);
153+
catch
154+
% Should not reach here; if so, throw unknown error.
155+
error('MUNIT:UnknownError', ...
156+
[mfilename, ' should not reach here.']);
157+
end
158+
return
159+
160+
161+
function test_assert_isequalwithequalnans_notequal_nansdiff(varargin)
162+
% Test Description: Test MU_assert_isequalwithequalnans, some values are NaNs.
163+
% Expected result: AssertionFailedError
164+
165+
x = [1:10];
166+
y = [1:10];
167+
x(2) = NaN;
168+
try
169+
MU_assert_isequalwithequalnans(x, y);
170+
171+
catch
172+
[errmsg, msg_id] = lasterr;
173+
switch(msg_id)
174+
case 'MUNIT:AssertionFailedError'
175+
% Success -- Expected result
176+
otherwise
177+
% Should not reach here; if so, throw unknow error.
178+
error('MUNIT:UnknownError', ...
179+
[mfilename, ' should not reach here.']);
180+
end
181+
end
182+
return
183+
184+
185+
function test_assert_fuzzy_diff(varargin)
186+
% Test Description: Test MU_assert_fuzzy_diff function.
187+
% Expected result: No error
188+
189+
if (nargin > 0)
190+
mode = varargin{1};
191+
end
192+
193+
194+
% Setup
195+
fuzzy_tol = 0;
196+
message = '';
197+
x = [1:10];
198+
y = x;
199+
200+
% Try equal within tolerance
201+
try
202+
MU_assert_fuzzy_diff(x, y, fuzzy_tol, message)
203+
if (strcmpi(mode, 'details'))
204+
disp('PASSED: fuzzy diff: a == b, fuzzy_tol = 0.0');
205+
end
206+
catch
207+
[errmsg, msg_id] = lasterr;
208+
switch(msg_id)
209+
otherwise
210+
% Should not reach here; if so, throw unknow error.
211+
error('MUNIT:UnknownError', ...
212+
[mfilename, ' should not reach here.']);
213+
end
214+
end
215+
216+
217+
% Try not equal within tolerance
218+
x = [1:10];
219+
y = x;
220+
221+
x(1) = 2;
222+
try
223+
MU_assert_fuzzy_diff(x, y, fuzzy_tol, message)
224+
catch
225+
[errmsg, msg_id] = lasterr;
226+
switch(msg_id)
227+
case 'MUNIT:AssertionFailedError'
228+
% Success -- Expected result
229+
if (strcmpi(mode, 'details'))
230+
disp('PASSED: fuzzy diff: a ~= b, fuzzy_tol = 0.0');
231+
end
232+
otherwise
233+
% Should not reach here; if so, throw unknow error.
234+
error('MUNIT:UnknownError', ...
235+
[mfilename, ' should not reach here.']);
236+
end
237+
end
238+
239+
240+
% Try equal -- within tolerance.
241+
x = [1:10];
242+
y = x;
243+
244+
x = x + .000002;
245+
y = y + .0000025;
246+
fuzzy_tol = .0000025;
247+
248+
try
249+
MU_assert_fuzzy_diff(x, y, fuzzy_tol, message)
250+
if (strcmpi(mode, 'details'))
251+
disp('PASSED: fuzzy diff: a == b, within fuzzy_tol = 0.0000025;');
252+
end
253+
catch
254+
[errmsg, msg_id] = lasterr;
255+
switch(msg_id)
256+
case 'MUNIT:AssertionFailedError'
257+
% Success -- Expected result
258+
otherwise
259+
% Should not reach here; if so, throw unknow error.
260+
error('MUNIT:UnknownError', ...
261+
[mfilename, ' should not reach here.']);
262+
end
263+
end
264+
265+
% Try equal -- out of tolerance.
266+
x = [1:10];
267+
y = x;
268+
x = x + .000002;
269+
y = y + .0000025;
270+
fuzzy_tol = .0000005;
271+
272+
try
273+
MU_assert_fuzzy_diff(x, y, fuzzy_tol, message)
274+
catch
275+
[errmsg, msg_id] = lasterr;
276+
switch(msg_id)
277+
case 'MUNIT:AssertionFailedError'
278+
% Success -- Expected result
279+
if (strcmpi(mode, 'details'))
280+
disp('PASSED: fuzzy diff: a == b, out of fuzzy_tol = 0.0000005;');
281+
end
282+
otherwise
283+
% Should not reach here; if so, throw unknow error.
284+
error('MUNIT:UnknownError', ...
285+
[mfilename, ' should not reach here.']);
286+
end
287+
end
288+
289+
return
290+
291+
292+
function test_assert_numsigdig_diff(varargin)
293+
% Test Description: Test MU_assert_numsigdig_diff function.
294+
% Expected result: No error
295+
296+
if (nargin > 0)
297+
mode = varargin{1};
298+
end
299+
300+
301+
% Setup
302+
numsigdig = 0;
303+
message = '';
304+
x = [1:10];
305+
y = x;
306+
y(2) = 0;
307+
308+
% Try equal.
309+
try
310+
MU_assert_numsigdig_diff(x, y, numsigdig, message)
311+
if (strcmpi(mode, 'details'))
312+
disp('PASSED: numsigdig diff: a == b, numsigdig = 0');
313+
end
314+
catch
315+
[errmsg, msg_id] = lasterr;
316+
switch(msg_id)
317+
otherwise
318+
% Should not reach here; if so, throw unknow error.
319+
error('MUNIT:UnknownError', ...
320+
[mfilename, ' should not reach here.']);
321+
end
322+
end
323+
324+
return
325+
326+
% Try equal -- within numsigdig.
327+
x = [1:10];
328+
y = x;
329+
x = x + .000002;
330+
y = y + .0000025;
331+
numsigdig = 6;
332+
333+
try
334+
MU_assert_numsigdig_diff(x, y, numsigdig, message)
335+
if (strcmpi(mode, 'details'))
336+
disp('PASSED: fuzzy diff: a == b, within numsigdig = 0.0000025;');
337+
end
338+
catch
339+
[errmsg, msg_id] = lasterr;
340+
switch(msg_id)
341+
case 'MUNIT:AssertionFailedError'
342+
% Success -- Expected result
343+
otherwise
344+
% Should not reach here; if so, throw unknow error.
345+
error('MUNIT:UnknownError', ...
346+
[mfilename, ' should not reach here.']);
347+
end
348+
end
349+
350+
return
351+
% Try equal -- out of tolerance.
352+
x = [1:10];
353+
y = [1:10];
354+
x = x + .000002;
355+
y = y + .0000025;
356+
numsigdig = .0000005;
357+
358+
try
359+
MU_assert_numsigdig_diff(x, y, numsigdig, message)
360+
catch
361+
[errmsg, msg_id] = lasterr;
362+
switch(msg_id)
363+
case 'MUNIT:AssertionFailedError'
364+
% Success -- Expected result
365+
if (strcmpi(mode, 'details'))
366+
disp('PASSED: fuzzy diff: a == b, out of numsigdig = 0.0000005;');
367+
end
368+
otherwise
369+
% Should not reach here; if so, throw unknow error.
370+
error('MUNIT:UnknownError', ...
371+
[mfilename, ' should not reach here.']);
372+
end
373+
end
374+
375+
return
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function external_test(varargin)
2+
% $Id: external_test.m 45 2004-11-17 03:55:41Z ccornish $
3+
test_name = mfilename;
4+
disp([test_name, ': This is external test']);
5+
return

0 commit comments

Comments
 (0)