forked from tjhickey724/OctaveBat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_everyNth.m
executable file
·31 lines (29 loc) · 992 Bytes
/
test_everyNth.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
function e = test_everyNth()
% test_everyNth() - runs unit tests on the everyNth function and returns number of tests that fail
% author: Tim Hickey
% date: 14 Feb 2011
%This is to see if this works
% Iain Crosby, runs fine, added one case to test code 'This is a string'
e=0;
e += runTest("Miracle",2,"Mrce");
e += runTest("abcdefg",2,"aceg");
e += runTest("abcdefg",3,"adg");
e += runTest("Chocolate",3,"Cca");
e += runTest("Chocolates",3,"Ccas");
e += runTest("Chocolates",4,"Coe");
e += runTest("Chocolates",100,"C");
e += runTest("This is a String", 3, "Tss rg"); %added by icrosby
end
function k = runTest(s,n,answer)
% runTest(s,n,answer) - checks that everyNth(s,n)==answer
% note the use of strcmp rather than == to test equality of strings!
result = everyNth(s,n);
if (strcmp(result,answer))
k=0;
printf(" everyNth(%s,%d)->%s\n",s,n,answer);
else
k=1;
printf("ERROR! everyNth(%s,%d)->%s <> %s\n",s,n,result,answer);
end
end
% Test Git