Skip to content

Commit 49a1c5d

Browse files
committed
Improved unit test
1 parent c79d3fb commit 49a1c5d

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,19 @@ set(SOURCE_FILES
1111
mapcodelib/mapcode_fastalpha.h
1212
mapcodelib/mapcoder.c
1313
mapcodelib/mapcoder.h
14-
unitttest/decode_test.h
15-
unitttest/test_territories.c
16-
unitttest/unittest.c
14+
unittest/decode_test.h
15+
unittest/test_territories.c
16+
unittest/unittest.c
1717
utility/mapcode.cpp)
1818

19-
add_executable(mapcode_cpp ${SOURCE_FILES})
19+
set(SOURCE_FILES_UNITTEST
20+
unittest/unittest.c)
21+
22+
set(SOURCE_FILES_UTILITY
23+
utility/mapcode.cpp)
24+
25+
add_executable(all ${SOURCE_FILES})
26+
27+
add_executable(unittest ${SOURCE_FILES_UNITTEST})
28+
29+
add_executable(mapcode ${SOURCE_FILES_UTILITY})

unittest/unittest.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ static void alphabet_tests() {
4040
printf("%d alphabets\n", MAPCODE_ALPHABETS_TOTAL);
4141

4242
for (i = 0; i < MAPCODE_ALPHABETS_TOTAL; i++) {
43-
UWORD enc[64];
44-
char dec[64];
43+
UWORD enc[69];
44+
char dec[69];
4545

4646
// see if convertToAlphabet survives empty string
4747
nrTests++;
4848
str = "";
4949
convertToAlphabet(enc, 64, str, i);
5050
if (*enc) {
5151
nrErrors++;
52-
printf("*** ERROR *** convertToAlphabet(\"%s\",%d) = \"%s\"\n", str, i, dec);
52+
printf("*** ERROR *** empty string: convertToAlphabet(\"%s\",%d) = \"%s\"\n", str, i, dec);
5353
}
5454
else {
5555
// see if empty UTF16 converts to empty string
@@ -62,40 +62,38 @@ static void alphabet_tests() {
6262
}
6363

6464
// see if alphabets (re)convert as expected
65-
str = "OEUoi OIoi#%?-.abcdfghjklmnpqrstvwxyz0123456789ABCDFGHJKLMNPQRSTVWXYZ";
66-
expect = "OEUoi OIOI#%?-.ABCDFGHJKLMNPQRSTVWXYZ0123456789ABCDFGHJKLMN";
67-
convertToAlphabet(enc, 64, str, i);
68-
convertToRoman(dec, 60, enc);
65+
str = "OEUoi OIoi#%?-.abcdfghjklmnpqrstvwxyz0123456789ABCDFGHJKLMNPQRSTVWXYZ";
66+
expect = "OEUoi OIOI#%?-.ABCDFGHJKLMNPQRSTVWXYZ0123456789ABCDFGHJKLMNPQRSTVWXYZ";
67+
convertToAlphabet(enc, sizeof(enc), str, i);
68+
convertToRoman(dec, sizeof(dec), enc);
6969
nrTests++;
7070
if (strlen(dec) != 59 || strcmp(dec, expect)) {
7171
nrErrors++;
72-
printf("*** ERROR *** convertToRoman(convertToAlphabet(\"%s\",%d))=\"%s\"\n", str, i, dec);
72+
printf("*** ERROR *** all chars: convertToRoman(convertToAlphabet(\"%s\",%d))=\"%s\", expected=\"%s\"\n", str, i, dec, expect);
7373
}
7474

7575
// see if E/U voweled mapcodes (re)convert as expected
7676
str = "OMN 112.3EU";
77-
convertToAlphabet(enc, 64, str, i);
78-
convertToRoman(dec, 64, enc);
77+
convertToAlphabet(enc, sizeof(enc), str, i);
78+
convertToRoman(dec, sizeof(dec), enc);
7979
nrTests++;
8080
if (strcmp(dec, str) != 0) {
8181
nrErrors++;
82-
printf("*** ERROR *** convertToRoman(convertToAlphabet(\"%s\",%d))=\"%s\"\n", str, i, dec);
82+
printf("*** ERROR *** vowels EU: convertToRoman(convertToAlphabet(\"%s\",%d))=\"%s\", expected=\"%s\"\n", str, i, dec, expect);
8383
}
8484
else {
8585
nrTests++;
8686
{
8787
str = " Oio 112.3AU ";
88-
convertToAlphabet(enc, 64, str, i);
89-
convertToRoman(dec, 64, enc);
88+
convertToAlphabet(enc, sizeof(enc), str, i);
89+
convertToRoman(dec, sizeof(dec), enc);
9090
nrTests++;
9191
if (strcmp(dec, "Oio 112.3AU") != 0) {
9292
nrErrors++;
93-
printf("*** ERROR *** convertToRoman(convertToAlphabet(\"%s\",%d))=\"%s\"\n", str, i, dec);
93+
printf("*** ERROR *** vowels AU: convertToRoman(convertToAlphabet(\"%s\",%d))=\"%s\"\n", str, i, dec);
9494
}
9595
}
9696
}
97-
98-
9997
}
10098
}
10199

0 commit comments

Comments
 (0)