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
|
#include "spm.h"
#include "framework.h"
const char *testFmt = "case '%s': returned %d, expected %d\n";
struct TestCase testCase[] = {
{.inputValue.unsigned_int = 'a', .caseValue.sptr = "after the world stops spinning", .truthValue.signed_int = 0},
{.inputValue.unsigned_int = 'p', .caseValue.sptr = "apples exploded all over the place", .truthValue.signed_int = 1},
{.inputValue.unsigned_int = '2', .caseValue.sptr = "a1a2a3a4a z!z@z#z$z a5a6a7a8a9", .truthValue.signed_int = 3},
{.inputValue.unsigned_int = 'a', .caseValue.sptr = "aAaA", .truthValue.signed_int = 0},
{.inputValue.unsigned_int = 'A', .caseValue.sptr = "aAaA", .truthValue.signed_int = 1},
{.inputValue.unsigned_int = 'g', .caseValue.sptr = "abracadabra brisket gumball", .truthValue.signed_int = 20},
{.inputValue.unsigned_int = 'r', .caseValue.sptr = "balloons are falling from the sky", .truthValue.signed_int = 10},
{.inputValue.unsigned_int = 'b', .caseValue.sptr = "mangled mangoes oxidize quickly", .truthValue.signed_int = -1},
{.inputValue.unsigned_int = 'b', .caseValue.sptr = "bBbB", .truthValue.signed_int = 0},
{.inputValue.unsigned_int = 'B', .caseValue.sptr = "bBbB", .truthValue.signed_int = 1},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
for (size_t i = 0; i < numCases; i++) {
int result = strchroff(testCase[i].caseValue.sptr, testCase[i].inputValue.unsigned_int);
myassert(result == testCase[i].truthValue.signed_int,
testFmt,
testCase[i].caseValue.sptr,
result,
testCase[i].truthValue.signed_int);
}
return 0;
}
|