Skip to content

Commit cd75753

Browse files
2.2.1 updated Unit test
1 parent cb58502 commit cd75753

File tree

1 file changed

+59
-6
lines changed

1 file changed

+59
-6
lines changed

unittest/unittest.html

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</head>
1616
<body>
1717

18-
Mapcode Javascript Unit Test 2.2<BR>
18+
Mapcode Javascript Unit Test 2.2.1<BR>
1919

2020
<DIV id="out"></DIV>
2121
<DIV id="perc"></DIV>
@@ -91,7 +91,7 @@
9191
if (r.length != localsolutions) {
9292
nrErrors++;
9393
out('*** ERROR *** encode(' + y.toFixed(10) + ', ' + x.toFixed(10) + ', "' + territory + '" ) does not deliver ' + localsolutions + ' solutions\n');
94-
printGeneratedMapcodes(r);
94+
printGeneratedMapcodes(r, territory);
9595
}
9696
}
9797

@@ -104,7 +104,7 @@
104104
if (!foundlocal) {
105105
nrErrors++;
106106
out('*** ERROR *** encode(' + y.toFixed(10) + ', ' + x.toFixed(10) + ', "' + territory + '" ) does not deliver "' + str + '"');
107-
printGeneratedMapcodes(r);
107+
printGeneratedMapcodes(r, territory);
108108
}
109109
}
110110

@@ -116,8 +116,8 @@
116116
nrTests++;
117117
if (r.length != globalsolutions) {
118118
nrErrors++;
119-
out('*** ERROR *** encode(' + y.toFixed(10) + ', ' + x.toFixed(10) + ') does not deliver ' + globalsolutions + ' solutions\n');
120-
printGeneratedMapcodes(r);
119+
out('*** ERROR *** encode(' + y.toFixed(10) + ', ' + x.toFixed(10) + ') does not deliver ' + globalsolutions + ' global solutions\n');
120+
printGeneratedMapcodes(r, territory);
121121
}
122122
}
123123

@@ -174,6 +174,7 @@
174174
else {
175175
nrErrors++;
176176
out('*** ERROR *** no result from decode(' + str + '), expected (' + y.toFixed(11) + ', ' + x.toFixed(11) + ')');
177+
printGeneratedMapcodes(r, "global");
177178
}
178179
}
179180
}
@@ -323,7 +324,7 @@
323324
if (needsParent == 0 && isAlias == 0 && (alphacode.length <= 3 || alphacode.charAt(3) != '-')) {
324325
nrTests++;
325326
var nam = getTerritoryAlphaCode(ccode);
326-
if (nam != alphacode && nam.indexOf('-' + alphacode) < 0) {
327+
if ((nam < 0) || (nam != alphacode && nam.indexOf('-' + alphacode) < 0)) {
327328
nrErrors++;
328329
out('*** ERROR *** getTerritoryAlphaCode(' + ccode + ')="' + nam + '" does not equal or contain "' + alphacode + '"');
329330
}
@@ -424,6 +425,57 @@
424425

425426
}
426427

428+
function territory_code_tests() {
429+
var testdata = [
430+
// expected answer, context, string
431+
"BR-AL", "BRA", "AL",
432+
"VAT", , "",
433+
"", , "R",
434+
"", , "RX",
435+
"", , "RXX",
436+
"RUS", , "RUS",
437+
"", , "RUSSIA",
438+
"USA", , "US",
439+
"USA", , "USA",
440+
"USA", , "usa",
441+
"USA", , " usa ",
442+
"", , "999",
443+
"", , "-44 33",
444+
"", , "666",
445+
"USA", , "410",
446+
"USA", , " 410 ",
447+
"USA", , "410 MORE TEXT",
448+
"USA", , "US CA",
449+
"", , "US-TEST",
450+
"USA", , "US OTHER TEXT",
451+
"USA", , " US OTHER TEXT ",
452+
"US-CA", , "US-CA",
453+
"US-CA", , "US-CA OTHER TEXT",
454+
"US-CA", , "USA-CA",
455+
"RU-TT", , "RUS-TAM",
456+
"", , "RUS-TAMX",
457+
"RU-TT", , "RUS-TAM X OTHER TEXT",
458+
"RU-AL", "rus", "AL",
459+
"RU-AL", "RUS", "AL",
460+
"RU-AL", "ru-tam", "AL",
461+
"RU-AL", "RU-TAM", "AL",
462+
"US-AL", "US", "AL",
463+
"US-AL", "US-CA", "AL",
464+
-9];
465+
466+
for (var i = 0; testdata[i] != -9; i += 3 ) {
467+
var tc = getTerritoryAlphaCode(getTerritoryNumber(testdata[i + 2], testdata[i + 1]));
468+
nrTests++;
469+
if (tc != testdata[i])
470+
{
471+
nrErrors++;
472+
out('*** ERROR *** getTerritoryNumber("' + testdata[i + 2] + '", ' +
473+
testdata[i + 1] + ')=' + tc + ', expected ' + testdata[i]);
474+
}
475+
}
476+
477+
}
478+
427479

428480
var myVar = setInterval(function () { stepper() }, 20);
429481
var dostep = 0;
@@ -446,6 +498,7 @@
446498
test_territory_insides();
447499
break;
448500
case 4:
501+
territory_code_tests();
449502
test_territories();
450503
break;
451504
case 5:

0 commit comments

Comments
 (0)