forked from tjhickey724/OctaveBat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_lone_sum.m
executable file
·41 lines (31 loc) · 1.03 KB
/
test_lone_sum.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
function test_lone_sum()
% test_lone_sum will test whether the function lone_sum works by
% comparing known answers to answers generated by lone_sum. This function
% calls on the function test_function for the comparison.
global error;
error = 0;
test_function(4, 4, 4, 0)
test_function(3, 5, 1, 9)
test_function(3, 5, 3, 5)
test_function(0, 9, 9, 0)
test_function(9, 8, 10, 27)
test_function(2, 2, 1, 1)
if error == 0
fprintf('The function works!\n')
else
fprintf('The function has errors\n')
end
end
function test_function(a,b,c,answer)
% test_function tests whether the function lone_sum equals the correct
% value as determined by people and prints a statement telling the user
% if the function works or not for the particular input values.
global error;
if lone_sum(a,b,c) == answer
fprintf('lone_sum(%d,%d,%d) = %d\n', a, b, c, answer)
else
fprintf('lone_sum(%d,%d,%d) does not equal %d. ERROR\n',...
a, b, c, answer)
error = error + 1;
end
end