-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-tzmap.html
71 lines (60 loc) · 1.94 KB
/
test-tzmap.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE HTML>
<script src="tzmap.js"></script>
<script>
var gOutput;
function print(s)
{
gOutput.appendData(s + "\n");
}
var pass_count = 0, fail_count = 0;
function assert(cond, description)
{
if (cond) {
++pass_count;
} else {
++fail_count;
print("FAIL: " + description);
}
}
function is(value, expected, description)
{
assert(value == expected,
description + ": " + value + " should equal " + expected);
}
window.addEventListener("load", run);
function run() {
gOutput = document.createTextNode("");
document.getElementById("output").appendChild(gOutput);
window.tzmap.loadData("./", if_success, if_failure);
}
function if_success() {
print("success loading JSON");
do_tests();
}
function if_failure() {
print("failure loading JSON");
}
function test_zone_at(lat, lon, n) {
is(window.tzmap.zoneAt(lat, lon), n, "zone at " + lat + "," + lon);
}
function test_zone_contains(lat, lon, n, expected) {
is(window.tzmap.zoneContains(n, lat, lon), expected, "zone " + n + " contains " + lat + "," + lon);
}
function do_tests() {
test_zone_at(-30, 20, "Africa/Johannesburg");
test_zone_contains(-30, 20, "Africa/Gaborone", false);
test_zone_at(40, -75, "America/New_York");
test_zone_contains(40, -75, "America/Iqaluit", false);
test_zone_contains(40, -75, "America/Nassau", false);
test_zone_contains(-10, -75, "America/Nassau", false);
test_zone_at(37.5, -122, "America/Los_Angeles");
test_zone_at(49, 4, "Europe/Paris");
test_zone_at(40, -65, null);
test_zone_at(-89, 100, "uninhabited");
window.tzmap.polygonsFor(["America/New_York"]);
window.tzmap.polygonsFor(["America/New_York", "America/Indiana/Indianapolis", "America/Kentucky/Louisville", "America/Kentucky/Monticello" ]);
window.tzmap.polygonsFor(["America/Iqaluit"]);
print("Totals: " + pass_count + " passed, " + fail_count + " failed.");
}
</script>
<pre id="output"></pre>