/
test_conditional_restrictions.cc
270 lines (242 loc) · 11.6 KB
/
test_conditional_restrictions.cc
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include "gurka.h"
#include <gtest/gtest.h>
#if !defined(VALHALLA_SOURCE_DIR)
#define VALHALLA_SOURCE_DIR
#endif
namespace {
const std::array<std::string, 3> kDateTimeTypes = {"1", "2", "3"};
const std::array<std::string, 6> kMotorVehicleCostingModels = {"auto", "bus",
"taxi", "motor_scooter",
"truck", "motorcycle"};
} // namespace
using namespace valhalla;
/*
* Tests the timeAllowed and timeDenied conditional restrictions for auto, bicycle and pedestrian
* costing. NOTE: To test restrictions, the map must contain more than 1 edge. If you only have 1
* edge, then it will never set the date_time info because its traversing a trivial path (see
* https://github.com/valhalla/valhalla/blob/master/src/thor/triplegbuilder.cc#L1216)
*/
class ConditionalRestrictions : public ::testing::Test {
protected:
static gurka::map map;
static void SetUpTestSuite() {
constexpr double grid_size_meters = 100;
const std::string ascii_map = R"(
A----B
| |
D C
\ /
E
F----G----H----I----J----K----L
| |
M----N
)";
const std::string condition =
"(Mar 00:00-07:00;Mar 17:30-24:00;Apr 00:00-07:00;Apr 19:00-24:00;Aug 00:00-07:00;Aug 19:00-24:00)";
const std::string timeDenied = "no @ " + condition;
const std::string yesAllowed = "yes @ " + condition;
const std::string privateAllowed = "private @ " + condition;
const std::string deliveryAllowed = "delivery @ " + condition;
const std::string designatedAllowed = "designated @ " + condition;
const std::string destinationAllowed = "destination @ " + condition;
const gurka::ways ways = {
{"AD",
{{"highway", "service"},
{"motorcar", "no"},
{"bicycle", "yes"},
{"foot", "yes"},
{"bicycle:conditional", yesAllowed},
{"foot:conditional", privateAllowed}}},
{"AB",
{{"highway", "service"},
{"motorcar:conditional", deliveryAllowed},
{"motorcycle:conditional", deliveryAllowed},
{"moped:conditional", deliveryAllowed},
{"psv:conditional", deliveryAllowed},
{"taxi:conditional", deliveryAllowed},
{"bus:conditional", deliveryAllowed},
{"hov:conditional", deliveryAllowed},
{"emergency:conditional", deliveryAllowed},
{"bicycle:conditional", timeDenied},
{"foot:conditional", designatedAllowed}}},
{"BC", {{"highway", "service"}, {"motorcar:conditional", destinationAllowed}}},
{"CD",
{{"highway", "service"},
{"motorcar:conditional", yesAllowed},
{"bicycle:conditional", timeDenied},
{"foot:conditional", privateAllowed}}},
{"DE",
{{"highway", "service"},
{"motorcar:conditional", deliveryAllowed},
{"bicycle:conditional", timeDenied},
{"foot:conditional", designatedAllowed}}},
{"CE",
{{"highway", "service"},
{"motorcar:conditional", destinationAllowed},
{"bicycle:conditional", timeDenied},
{"foot:conditional", yesAllowed}}},
{"FG", {{"highway", "residential"}}},
{"GH", {{"highway", "residential"}}},
{"HI", {{"highway", "residential"}, {"motor_vehicle:conditional", destinationAllowed}}},
{"IJ", {{"highway", "residential"}}},
{"JK", {{"highway", "residential"}, {"motor_vehicle:conditional", destinationAllowed}}},
{"KL", {{"highway", "residential"}}},
{"JM", {{"highway", "residential"}}},
{"MN", {{"highway", "residential"}}},
{"NK", {{"highway", "residential"}}},
};
const auto layout = gurka::detail::map_to_coordinates(ascii_map, grid_size_meters);
map = gurka::buildtiles(layout, ways, {}, {},
VALHALLA_BUILD_DIR "test/data/conditional_restrictions",
{{"mjolnir.timezone", {VALHALLA_BUILD_DIR "test/data/tz.sqlite"}}});
}
};
gurka::map ConditionalRestrictions::map = {};
/*************************************************************/
TEST_F(ConditionalRestrictions, NoRestrictionAutoNoDate) {
auto result = gurka::do_action(valhalla::Options::route, map, {"A", "E"}, "auto");
gurka::assert::osrm::expect_steps(result, {"AB", "BC", "CE"});
gurka::assert::raw::expect_path(result, {"AB", "BC", "CE"});
}
TEST_F(ConditionalRestrictions, NoRestrictionAuto) {
auto result =
gurka::do_action(valhalla::Options::route, map, {"A", "E"}, "auto",
{{"/date_time/type", "1"}, {"/date_time/value", "2020-04-15T06:00"}});
gurka::assert::osrm::expect_steps(result, {"AB", "BC", "CE"});
gurka::assert::raw::expect_path(result, {"AB", "BC", "CE"});
}
TEST_F(ConditionalRestrictions, RestrictionAuto) {
auto result =
gurka::do_action(valhalla::Options::route, map, {"A", "E"}, "auto",
{{"/date_time/type", "1"}, {"/date_time/value", "2020-04-02T12:00"}});
gurka::assert::osrm::expect_steps(result, {"AB", "BC", "CE"});
gurka::assert::raw::expect_path(result, {"AB", "BC", "CE"});
}
TEST_F(ConditionalRestrictions, NoRestrictionBikeNoDate) {
auto result = gurka::do_action(valhalla::Options::route, map, {"A", "E"}, "bicycle");
gurka::assert::osrm::expect_steps(result, {"AD", "DE"});
gurka::assert::raw::expect_path(result, {"AD", "DE"});
}
TEST_F(ConditionalRestrictions, NoRestrictionBike) {
auto result =
gurka::do_action(valhalla::Options::route, map, {"A", "E"}, "bicycle",
{{"/date_time/type", "1"}, {"/date_time/value", "2020-04-02T12:00"}});
gurka::assert::osrm::expect_steps(result, {"AD", "DE"});
gurka::assert::raw::expect_path(result, {"AD", "DE"});
}
TEST_F(ConditionalRestrictions, RestrictionBike) {
// this tests that the expected exception is thrown
EXPECT_THROW(
{
try {
auto result =
gurka::do_action(valhalla::Options::route, map, {"A", "E"}, "bicycle",
{{"/date_time/type", "1"}, {"/date_time/value", "2020-04-02T20:00"}});
} catch (const std::exception& e) {
// and this tests that it has the correct message
EXPECT_STREQ("No path could be found for input", e.what());
throw;
}
},
std::exception);
}
TEST_F(ConditionalRestrictions, NoRestrictionPedestrianNoDate) {
auto result = gurka::do_action(valhalla::Options::route, map, {"A", "E"}, "pedestrian");
gurka::assert::osrm::expect_steps(result, {"AD", "DE"});
gurka::assert::raw::expect_path(result, {"AD", "DE"});
}
TEST_F(ConditionalRestrictions, NoRestrictionPedestrian) {
auto result =
gurka::do_action(valhalla::Options::route, map, {"A", "E"}, "pedestrian",
{{"/date_time/type", "1"}, {"/date_time/value", "2020-04-02T20:00"}});
gurka::assert::osrm::expect_steps(result, {"AD", "DE"});
gurka::assert::raw::expect_path(result, {"AD", "DE"});
}
TEST_F(ConditionalRestrictions, RestrictionPedestrian) {
// this tests that the expected exception is thrown
EXPECT_THROW(
{
try {
auto result =
gurka::do_action(valhalla::Options::route, map, {"A", "E"}, "pedestrian",
{{"/date_time/type", "1"}, {"/date_time/value", "2020-04-02T12:00"}});
} catch (const std::exception& e) {
// and this tests that it has the correct message
EXPECT_STREQ("No path could be found for input", e.what());
throw;
}
},
std::exception);
}
TEST_F(ConditionalRestrictions, DestinationRestrictionOnLastEdgeIsValid) {
for (auto const& date_time_type : kDateTimeTypes) {
for (auto const& costing : kMotorVehicleCostingModels) {
auto result = gurka::do_action(valhalla::Options::route, map, {"F", "I"}, costing,
{{"/date_time/type", date_time_type},
{"/date_time/value", "2020-04-04T20:00"}});
gurka::assert::raw::expect_path(result, {"FG", "GH", "HI"},
"Date time type: " + date_time_type +
", costing type: " + costing);
}
}
}
TEST_F(ConditionalRestrictions, DestinationRestrictionOnLastEdgeIsNotValid) {
for (auto const& date_time_type : kDateTimeTypes) {
for (auto const& costing : kMotorVehicleCostingModels) {
auto result = gurka::do_action(valhalla::Options::route, map, {"F", "I"}, costing,
{{"/date_time/type", date_time_type},
{"/date_time/value", "2020-04-04T12:00"}});
gurka::assert::raw::expect_path(result, {"FG", "GH", "HI"},
"Date time type: " + date_time_type +
", costing type: " + costing);
}
}
}
TEST_F(ConditionalRestrictions, DestinationRestrictionOnMidEdgeIsValid_OnlyAlternative) {
for (auto const& date_time_type : kDateTimeTypes) {
for (auto const& costing : kMotorVehicleCostingModels) {
auto result = gurka::do_action(valhalla::Options::route, map, {"F", "J"}, costing,
{{"/date_time/type", date_time_type},
{"/date_time/value", "2020-04-04T20:00"}});
gurka::assert::raw::expect_path(result, {"FG", "GH", "HI", "IJ"},
"Date time type: " + date_time_type +
", costing type: " + costing);
}
}
}
TEST_F(ConditionalRestrictions, DestinationRestrictionOnMidEdgeIsNotValid_OnlyAlternative) {
for (auto const& date_time_type : kDateTimeTypes) {
for (auto const& costing : kMotorVehicleCostingModels) {
auto result = gurka::do_action(valhalla::Options::route, map, {"F", "J"}, costing,
{{"/date_time/type", date_time_type},
{"/date_time/value", "2020-04-04T12:00"}});
gurka::assert::raw::expect_path(result, {"FG", "GH", "HI", "IJ"},
"Date time type: " + date_time_type +
", costing type: " + costing);
}
}
}
TEST_F(ConditionalRestrictions, DestinationRestrictionOnMidEdgeIsValid_ManyAlternatives) {
for (auto const& date_time_type : kDateTimeTypes) {
for (auto const& costing : kMotorVehicleCostingModels) {
auto result = gurka::do_action(valhalla::Options::route, map, {"I", "L"}, costing,
{{"/date_time/type", date_time_type},
{"/date_time/value", "2020-04-04T20:00"}});
gurka::assert::raw::expect_path(result, {"IJ", "JM", "MN", "NK", "KL"},
"Date time type: " + date_time_type +
", costing type: " + costing);
}
}
}
TEST_F(ConditionalRestrictions, DestinationRestrictionOnMidEdgeIsNotValid_ManyAlternatives) {
for (auto const& date_time_type : kDateTimeTypes) {
for (auto const& costing : kMotorVehicleCostingModels) {
auto result = gurka::do_action(valhalla::Options::route, map, {"I", "L"}, costing,
{{"/date_time/type", date_time_type},
{"/date_time/value", "2020-04-04T12:00"}});
gurka::assert::raw::expect_path(result, {"IJ", "JK", "KL"},
"Date time type: " + date_time_type +
", costing type: " + costing);
}
}
}