-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_close_far.m
executable file
·45 lines (35 loc) · 1.22 KB
/
test_close_far.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 test_close_far()
% test_close_far will test whether the function close_far works by
% comparing known answers to answers generated by close_far. This function
% calls on the function test_function for the comparison.
#modified by Ben Setel. Added the last three tests.
global error;
error = 0;
test_function(1, 2, 3, false)
test_function(1, 1, 3, true)
test_function(2, 10, 3, true)
test_function(1, 10, 11, false)
test_function(9, 8, 10, false)
test_function(5, 4, 2, true)
test_function(-5, 4, 2, false) #added
test_function(-3, 4, 2, false) #added
test_function(-1, 0, 2, true) #added
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 close_far 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 closeFar(a,b,c) == answer
fprintf('closeFar(%d,%d,%d) = %d\n', a, b, c, answer)
else
fprintf('closeFar(%d,%d,%d) does not equal %d. ERROR\n',...
a, b, c, answer)
error = error + 1;
end
end