This repository has been archived by the owner on Apr 15, 2018. It is now read-only.
forked from ClearTables/ClearTables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-transportation.lua
138 lines (115 loc) · 8.98 KB
/
test-transportation.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
--[[
This file is part of ClearTables
@author Paul Norman <penorman@mac.com>
@copyright 2015-2016 Paul Norman, MIT license
]]--
require "transportation"
print("transportation.lua tests")
print("TESTING: brunnel")
assert(brunnel({}) == nil, "test failed: nil")
assert(brunnel({bridge="yes"}) == "bridge", "test failed: bridge=yes")
assert(brunnel({bridge="no"}) == nil, "test failed: bridge=no")
assert(brunnel({tunnel="yes"}) == "tunnel", "test failed: tunnel=yes")
assert(brunnel({tunnel="no"}) == nil, "test failed: tunnel=no")
assert(brunnel({bridge="yes", tunnel="yes"}) == "bridge", "test failed: tunnel+bridge")
print("TESTING: lanes")
assert(lanes(nil) == nil, "test failed: nil")
assert(lanes("0") == nil, "test failed: 0")
assert(lanes("-1") == nil, "test failed: -1")
assert(lanes("1") == "1", "test failed: 1")
assert(lanes("1.5") == nil, "test failed: 1.5")
assert(lanes("foo") == nil, "test failed: text")
assert(lanes("f1") == nil, "test failed: char num")
assert(lanes("1f") == nil, "test failed: num char")
print("TESTING: speed")
assert(speed(nil) == nil, "test failed: nil")
assert(speed("foo") == nil, "test failed: foo")
assert(speed("70 foo") == nil, "test failed: 70 foo")
assert(speed("70") == "70", "test failed: 70")
assert(speed("-70") == nil, "test failed: -70")
assert(speed("70.5") == "70.5", "test failed: 70.5")
assert(speed("1234") == nil, "test failed: out of range")
assert(speed("10 mph") == "16.09", "test failed: mph with space")
assert(speed("10mph") == "16.09", "test failed: mph without space")
assert(speed("12.5 mph") == "20.1125", "test failed: decimal mph with space")
assert(speed("12.5mph") == "20.1125", "test failed: decimal mph without space")
assert(speed("10mph0") == nil, "test failed: mph in middle")
assert(speed("RO:urban") == "50", "test failed: RO:urban")
assert(speed("80;100") == nil, "test failed: 80;100")
print("TESTING: accept_road")
assert(not accept_road({}), "test failed: untagged")
assert(not accept_road({foo="bar"}), "test failed: other tags")
assert(not accept_road({highway="bar"}), "test failed: other highway tag")
-- Test one non-ramp, unknown, and ramp
assert(accept_road({highway="motorway"}), "test failed: motorway")
assert(accept_road({highway="residential"}), "test failed: residential")
assert(accept_road({highway="motorway_link"}), "test failed: motorway_link")
print("TESTING: accept_rail")
assert(not accept_rail({}), "test failed: untagged")
assert(not accept_rail({foo="bar"}), "test failed: other tags")
assert(not accept_rail({railway="bar"}), "test failed: other railway tag")
assert(accept_rail({railway="rail"}), "test failed: rail")
print("TESTING: transform_road")
assert(deepcompare(transform_road({}), {}), "test failed: no tags")
assert(deepcompare(transform_road({name="foo"}), {name="foo"}), "test failed: name")
assert(deepcompare(transform_road({["name:en"]="foo"}), {names='"en"=>"foo"'}), "test failed: names")
assert(deepcompare(transform_road({ref="a;b"}), {refs='{"a","b"}'}), "test failed: ref")
assert(transform_road({highway="motorway", maxspeed="80"}).maxspeed == "80", "test failed: maxspeed")
assert(transform_road({highway="motorway"}).class == "motorway", "test failed: motorway class")
assert(transform_road({highway="motorway_link"}).class == "motorway", "test failed: motorway_link class")
assert(transform_road({highway="road"}).class == "unknown", "test failed: road class")
assert(transform_road({highway="pedestrian"}).class == "path", "test failed: pedestrian class")
assert(transform_road({highway="motorway"}).ramp == "false", "test failed: motorway ramp")
assert(transform_road({highway="motorway_link"}).ramp == "true", "test failed: motorway_link ramp")
assert(transform_road({highway="road"}).ramp == nil, "test failed: road ramp")
assert(transform_road({highway="pedestrian"}).ramp == nil, "test failed: pedestrian ramp")
assert(transform_road({highway="residential", motor_vehicle="yes"}).motor_access == "yes", "test failed: residential motor motor_vehicle yes")
assert(transform_road({highway="residential", motor_vehicle="no"}).motor_access == "no", "test failed: residential motor motor_vehicle no")
assert(transform_road({highway="residential", vehicle="yes"}).motor_access == "yes", "test failed: residential motor motor_vehicle yes")
assert(transform_road({highway="residential", vehicle="no"}).motor_access == "no", "test failed: residential motor motor_vehicle no")
assert(transform_road({highway="residential", access="yes"}).motor_access == "yes", "test failed: residential motor access yes")
assert(transform_road({highway="residential", access="no"}).motor_access == "no", "test failed: residential motor access no")
assert(transform_road({highway="residential", bicycle="yes"}).bicycle_access == "yes", "test failed: residential bicycle bicycle_access yes")
assert(transform_road({highway="residential", bicycle="no"}).bicycle_access == "no", "test failed: residential bicycle bicycle_access no")
assert(transform_road({highway="residential", vehicle="yes"}).bicycle_access == "yes", "test failed: residential bicycle bicycle_access yes")
assert(transform_road({highway="residential", vehicle="no"}).bicycle_access == "no", "test failed: residential bicycle bicycle_access no")
assert(transform_road({highway="residential", access="yes"}).bicycle_access == "yes", "test failed: residential bicycle bicycle_access yes")
assert(transform_road({highway="residential", access="no"}).bicycle_access == "no", "test failed: residential bicycle bicycle_access no")
assert(transform_road({highway="residential", bridge="yes"}).brunnel == "bridge", "test failed: bridge")
assert(transform_road({highway="residential", tunnel="yes"}).brunnel == "tunnel", "test failed: tunnel")
assert(transform_road({highway="residential", bridge="yes", tunnel="yes"}).brunnel == "bridge", "test failed: bridge+tunnel")
assert(transform_road({highway="residential"}).layer == "0", "test failed: layer 0")
assert(transform_road({highway="residential", layer="4"}).layer == "4", "test failed: layer 4")
assert(transform_road({highway="residential", oneway="yes"}).oneway == "true", "test failed: residential oneway=yes")
assert(transform_road({highway="residential", oneway="no"}).oneway == "false", "test failed: residential oneway=no")
assert(transform_road({highway="residential", oneway="-1"}).oneway == "reverse", "test failed: residential oneway=-1")
assert(transform_road({highway="residential"}).oneway == nil, "test failed: residential no oneway")
assert(transform_road({highway="motorway_link", oneway="yes"}).oneway == "true", "test failed: motorway_link oneway=yes")
assert(transform_road({highway="motorway_link", oneway="no"}).oneway == "false", "test failed: motorway_link oneway=no")
assert(transform_road({highway="motorway_link", oneway="-1"}).oneway == "reverse", "test failed: motorway_link oneway=-1")
assert(transform_road({highway="motorway_link"}).oneway == "true", "test failed: motorway_link no oneway")
assert(transform_road({highway="residential", junction="roundabout", oneway="yes"}).oneway == "true", "test failed: junction oneway=yes")
assert(transform_road({highway="residential", junction="roundabout", oneway="no"}).oneway == "false", "test failed: junction oneway=no")
assert(transform_road({highway="residential", junction="roundabout", oneway="-1"}).oneway == "reverse", "test failed: junction oneway=-1")
assert(transform_road({highway="residential", junction="roundabout"}).oneway == "true", "test failed: junction no oneway")
print("TESTING: accept_road_point")
assert(not accept_road_point({}), "test failed: untagged")
assert(not accept_road_point({foo="bar"}), "test failed: other tags")
assert(not accept_road_point({highway="bar"}), "test failed: other highway tag")
assert(accept_road_point({highway="crossing"}), "test failed: crossing")
assert(accept_road_point({highway="traffic_signals"}), "test failed: traffic_signals")
assert(accept_road_point({highway="motorway_junction"}), "test failed: motorway_junction")
print("TESTING: transform_road_point")
assert(deepcompare(transform_road_point({}), {}), "test failed: no tags")
assert(transform_road_point({name="foo"}).name == "foo", "test failed: name")
assert(transform_road_point({["name:en"]="foo"}), {names='"en"=>"foo"'}, "test failed: names")
assert(transform_road_point({ref="A1"}).ref == "A1", "test failed: ref")
assert(transform_road_point({highway="crossing"}).type == "crossing", "test failed: highway")
print("TESTING: transform_rail")
assert(deepcompare(transform_rail({}), {}), "test failed: no tags")
assert(transform_rail({name="foo"}).name == "foo", "test failed: name")
assert(transform_rail({["name:en"]="foo"}).names == '"en"=>"foo"', "test failed: names")
assert(transform_rail({railway="subway"}).class == "transit", "test failed: subway class")
assert(transform_rail({railway="rail", bridge="yes"}).brunnel == "bridge", "test failed: bridge")
assert(transform_rail({railway="rail", tunnel="yes"}).brunnel == "tunnel", "test failed: tunnel")
assert(transform_rail({railway="rail", bridge="yes", tunnel="yes"}).brunnel == "bridge", "test failed: bridge+tunnel")