-
Notifications
You must be signed in to change notification settings - Fork 0
/
hikemap_tagtransform_tests.lua
160 lines (127 loc) · 3.57 KB
/
hikemap_tagtransform_tests.lua
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
-- Unit tests for functions in hikemap_tagtransform
require('luaunit')
require('hikemap_tagtransform')
-------------- Road classification ---------------
-- Interstates
function test_classify_interstate_1()
kvs = {highway='motorway', ref='I-90'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'I')
assertEquals(kvs['road_ref'], '90')
end
function test_classify_interstate_2()
kvs = {highway='motorway', ref='I 295'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'I')
assertEquals(kvs['road_ref'], '295')
end
function test_classify_interstate_3()
kvs = {highway='motorway', ref='I90'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'I')
assertEquals(kvs['road_ref'], '90')
end
-- US Highways
function test_classify_us_1()
kvs = {highway='trunk', ref='US 1'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'U')
assertEquals(kvs['road_ref'], '1')
end
function test_classify_us_2()
kvs = {highway='trunk', ref=' US-44'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'U')
assertEquals(kvs['road_ref'], '44')
end
function test_classify_us_3()
kvs = {highway='trunk', ref='US12A'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'U')
assertEquals(kvs['road_ref'], '12A')
end
-- State routes
function test_classify_state_1()
kvs = {highway='primary', ref='SR 12A'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'S')
assertEquals(kvs['road_ref'], '12A')
end
function test_classify_state_2()
kvs = {highway='primary', ref='SR-6'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'S')
assertEquals(kvs['road_ref'], '6')
end
function test_classify_state_ma()
kvs = {highway='primary', ref='MA 128'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'S')
assertEquals(kvs['road_ref'], '128')
end
function test_classify_state_nh()
kvs = {highway='primary', ref='NH 5'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'S')
assertEquals(kvs['road_ref'], '5')
end
function test_classify_state_vt()
kvs = {highway='primary', ref='VT 131'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'S')
assertEquals(kvs['road_ref'], '131')
end
-- Other routes
function test_classify_county_route()
kvs = {highway='secondary', ref='CR 32'}
classify_road(kvs);
assertEquals(kvs['road_class'], nil)
assertEquals(kvs['road_ref'], '32')
end
-- Combined routes (only first one is significant)
function test_classify_combo()
kvs = {highway='primary', ref='US2;MA 32'}
classify_road(kvs);
assertEquals(kvs['road_class'], 'U')
assertEquals(kvs['road_ref'], '2')
end
-- Not a numbered route
function test_classify_none_1()
kvs = {highway='primary', ref='abc'}
classify_road(kvs);
assertEquals(kvs['road_class'], nil)
assertEquals(kvs['road_ref'], nil)
end
function test_classify_none_2()
kvs = {highway='primary'}
classify_road(kvs);
assertEquals(kvs['road_class'], nil)
assertEquals(kvs['road_ref'], nil)
end
-- Weird edge cases
function test_classify_edge_1()
kvs = {highway='primary', ref=";"}
classify_road(kvs);
assertEquals(kvs['road_class'], nil)
assertEquals(kvs['road_ref'], nil)
end
function test_classify_edge_2()
kvs = {highway='primary', ref=";US 1"}
classify_road(kvs);
assertEquals(kvs['road_class'], nil)
assertEquals(kvs['road_ref'], nil)
end
function test_classify_edge_3()
kvs = {highway='primary', ref="US 1;"}
classify_road(kvs);
assertEquals(kvs['road_class'], 'U')
assertEquals(kvs['road_ref'], '1')
end
function test_classify_edge_4()
kvs = {highway='primary', ref=""}
classify_road(kvs);
assertEquals(kvs['road_class'], nil)
assertEquals(kvs['road_ref'], nil)
end
lu = LuaUnit.new()
os.exit(lu:runSuite())