|
15 | 15 | </head> |
16 | 16 | <body> |
17 | 17 |
|
18 | | -Mapcode Javascript Unit Test 2.2<BR> |
| 18 | +Mapcode Javascript Unit Test 2.2.1<BR> |
19 | 19 |
|
20 | 20 | <DIV id="out"></DIV> |
21 | 21 | <DIV id="perc"></DIV> |
|
91 | 91 | if (r.length != localsolutions) { |
92 | 92 | nrErrors++; |
93 | 93 | out('*** ERROR *** encode(' + y.toFixed(10) + ', ' + x.toFixed(10) + ', "' + territory + '" ) does not deliver ' + localsolutions + ' solutions\n'); |
94 | | - printGeneratedMapcodes(r); |
| 94 | + printGeneratedMapcodes(r, territory); |
95 | 95 | } |
96 | 96 | } |
97 | 97 |
|
|
104 | 104 | if (!foundlocal) { |
105 | 105 | nrErrors++; |
106 | 106 | out('*** ERROR *** encode(' + y.toFixed(10) + ', ' + x.toFixed(10) + ', "' + territory + '" ) does not deliver "' + str + '"'); |
107 | | - printGeneratedMapcodes(r); |
| 107 | + printGeneratedMapcodes(r, territory); |
108 | 108 | } |
109 | 109 | } |
110 | 110 |
|
|
116 | 116 | nrTests++; |
117 | 117 | if (r.length != globalsolutions) { |
118 | 118 | 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); |
121 | 121 | } |
122 | 122 | } |
123 | 123 |
|
|
174 | 174 | else { |
175 | 175 | nrErrors++; |
176 | 176 | out('*** ERROR *** no result from decode(' + str + '), expected (' + y.toFixed(11) + ', ' + x.toFixed(11) + ')'); |
| 177 | + printGeneratedMapcodes(r, "global"); |
177 | 178 | } |
178 | 179 | } |
179 | 180 | } |
|
323 | 324 | if (needsParent == 0 && isAlias == 0 && (alphacode.length <= 3 || alphacode.charAt(3) != '-')) { |
324 | 325 | nrTests++; |
325 | 326 | var nam = getTerritoryAlphaCode(ccode); |
326 | | - if (nam != alphacode && nam.indexOf('-' + alphacode) < 0) { |
| 327 | + if ((nam < 0) || (nam != alphacode && nam.indexOf('-' + alphacode) < 0)) { |
327 | 328 | nrErrors++; |
328 | 329 | out('*** ERROR *** getTerritoryAlphaCode(' + ccode + ')="' + nam + '" does not equal or contain "' + alphacode + '"'); |
329 | 330 | } |
|
424 | 425 |
|
425 | 426 | } |
426 | 427 |
|
| 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 | + |
427 | 479 |
|
428 | 480 | var myVar = setInterval(function () { stepper() }, 20); |
429 | 481 | var dostep = 0; |
|
446 | 498 | test_territory_insides(); |
447 | 499 | break; |
448 | 500 | case 4: |
| 501 | + territory_code_tests(); |
449 | 502 | test_territories(); |
450 | 503 | break; |
451 | 504 | case 5: |
|
0 commit comments