-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_loneSum.m
executable file
·58 lines (48 loc) · 1.48 KB
/
test_loneSum.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
46
47
48
49
50
51
52
53
54
55
56
57
58
function e = test_loneSum()
% test_loneSum() runs several tests and returns the number of tests that
% fail.
%
% Adam Rosenbloom on 3-1-2011
% Sara Shahanaghi--added two additional tests
% Yohanes Santoso - added tests
e = 0;
e = e + runtest(1, 2, 3, 6);
e = e + runtest(3, 2, 3, 2);
e = e + runtest(3, 3, 3, 0);
e = e + runtest(9, 9, 1, 1);
e = e + runtest(3, 7, 7, 3);
e = e + runtest(9, 7, 3, 19);
e = e + runtest(11, 6, 6, 11);
e = e + runtest(18, 22, 18, 22);
e = e + runtest(22, 22, 7, 7);
e = e + runtest(11, 11, 11, 0);
e = e + runtest(1, 99, 3, 103);
e = e + runtest(0, 0, 6, 6);
e = e + runtest(9, 2, 2, 9);% by Robin Jha
e = e + runtest(3, 1, 1, 3);% by Robin Jha
e = e + runtest(2, 9, 3, 14);% by Robin Jha
<<<<<<< HEAD
e = e + runtest(sqrt(1), sqrt(4), sqrt(9), 6); % Abhirup Das added one test
=======
e = e + runtest(0, 0, 0, 0);
e = e + runtest(100, 100, 100, 100)
>>>>>>> c547ede29ac2995af4fad794a5cd566bb1b84524
if e == 0
fprintf('Tests succesful!')
else
fprintf('One or more tests failed!')
end
end
function e = runtest(a, b, c, answer)
% runtest(a, b, c, answer) calls loneSum(a, b, c) to get the result, compares with
% the answer and returns true (1) if there is an error and false (0) if
% there is not. Displays test results.
result = loneSum(a, b, c);
if (result == answer)
e = 0;
fprintf('\tloneSum(%d, %d, %d) = %d\n', a, b, c, result)
else
e = 1;
fprintf('\tERROR: loneSum(%d, %d, %d) returned %d\n\t\t%d expected\n', a, b, c, result, answer)
end
end