-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_groupSum.m
executable file
·40 lines (31 loc) · 993 Bytes
/
test_groupSum.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
function e = test_groupSum()
#Jeremy Patton
# Tested by:
# Josh Silverman (add negative test cases, otherwise good coverage)
e=0;
e+=runTest(1, [2, 4, 8], 10, 1);
e+=runTest(1, [2, 4, 8], 14, 1);
e+=runTest(1, [2, 4, 8], 9, 0);
e+=runTest(1, [2, 4, 8], 8, 1);
e+=runTest(2, [2, 4, 8], 8, 1);
e+=runTest(2, [2, 4, 8], 2, 0);
e+=runTest(1, [1], 1, 1);
e+=runTest(1, [9], 1, 0);
e+=runTest(2, [9], 0, 1);
e+=runTest(1, [], 0, 1);
e+=runTest(1, [10, 2, 2, 5], 17, 1);
e+=runTest(1, [10, 2, 2, 5], 15, 1);
e+=runTest(1, [10, 2, 2, 5], 9, 1);
e+=runTest(1, [10, -1], 9, 1);
e+=runTest(1, [10, -5,], 9, 0);
end
function k = runTest(start, nums, target, answer)
result = groupSum(start,nums,target);
if(result==answer)
k=0;
printf(" groupSum(%d, [", start); printf("%d ",nums); printf("], %d) %d -> %d\n", target, result, answer);
else
k=1;
printf("ERROR! g groupSum(%d, [", start); printf("%d ",nums); printf("], %d) %d <-> %d\n", target, result, answer);
end
end