-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_frontBack.m
executable file
·45 lines (34 loc) · 1.03 KB
/
test_frontBack.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function y = test_frontBack();
% test_frontBack runs several tests on the
% frontBack function, displays frontBack's
% output for each test,
% and returns the number of tests that fail.
% Author: Gabriel Bronk
% 3/2/11
y = 0;
y = y + runtest('computers','somputerc');
y = y + runtest('will','lilw');
y = y + runtest('conquer','ronquec');
y = y + runtest('Earth','hartE');
y = y + runtest('Oh no!','!h noO');
y = y + runtest('be','eb');
y = y + runtest('antidisestablishmentarianism','mntidisestablishmentarianisa');
y = y + runtest('a','a');
y = y + runtest('radar','radar');
y = y + runtest(' radar','rrada ');
end
function q = runtest(a,answer);
% runtest(a,answer) calls frontBack(a)
% to get the result, compares with the answer
% and returns 1 if an error, 0 if not.
% It also prints out the test results.
result = frontBack(a);
if (result == answer);
q = 0;
fprintf('frontBack(%s)=%s\n',a,result);
else
q = 1;
fprintf('ERROR:frontBack(%s)->%s <> %s\n',
a,result,answer);
end
end