/
signinfo.cc
253 lines (204 loc) · 10.4 KB
/
signinfo.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
#include "baldr/signinfo.h"
#include "baldr/graphid.h"
#include "mjolnir/uniquenames.h"
#include "test.h"
#include "mjolnir/graphbuilder.h"
using namespace valhalla::mjolnir;
using namespace valhalla::baldr;
using valhalla::mjolnir::GraphBuilder;
namespace {
TEST(Signinfo, ExitToTest) {
OSMNode node{1234};
OSMNode exit_node{1234};
OSMWay way{};
OSMData osmdata{};
std::map<std::pair<uint8_t, uint8_t>, uint32_t> pronunciationMap;
const std::map<std::pair<uint8_t, uint8_t>, uint32_t> langMap;
bool fork = false;
bool forward = true;
exit_node.set_ref_index(osmdata.node_names.index("5"));
exit_node.set_name_index(osmdata.node_names.index("PATP West Exit"));
std::vector<SignInfo> signs;
std::vector<std::string> linguistics;
std::vector<std::pair<std::string, bool>> default_languages;
const std::string linguistic_node_file = "test_sign_linguistic_node.bin";
sequence<OSMNodeLinguistic> linguistic_node(linguistic_node_file, true);
bool has_guide = GraphBuilder::CreateSignInfoList(exit_node, way, pronunciationMap, langMap,
osmdata, default_languages, linguistic_node,
signs, linguistics, fork, forward, true, false);
EXPECT_FALSE(has_guide) << "Exits should not be Guides";
if (signs.size() == 2) {
EXPECT_EQ(signs[0].type(), Sign::Type::kExitNumber) << "Exit 5 is not an exit Number";
EXPECT_EQ(signs[0].text(), "5") << "Exitsign text is bad for Exit 5.";
EXPECT_EQ(signs[1].type(), Sign::Type::kExitName) << "PATP West Exit is not an exit Name";
EXPECT_EQ(signs[1].text(), "PATP West Exit") << "Exitsign text is bad for PATP West Exit.";
} else {
FAIL() << "Exit 5 failed to parse.";
}
node.set_exit_to_index(osmdata.node_names.index("US 11;To I 81;Carlisle;Harrisburg"));
signs.clear();
has_guide = GraphBuilder::CreateSignInfoList(node, way, pronunciationMap, langMap, osmdata,
default_languages, linguistic_node, signs, linguistics,
fork, forward, true, false);
EXPECT_FALSE(has_guide) << "Exits should not be Guides";
if (signs.size() == 4) {
for (auto& exitsign : signs) {
EXPECT_EQ(exitsign.type(), Sign::Type::kExitToward)
<< "US 11;To I 81;Carlisle;Harrisburg types are not all Toward";
}
EXPECT_EQ(signs[0].text(), "US 11");
EXPECT_EQ(signs[1].text(), "I 81");
EXPECT_EQ(signs[2].text(), "Carlisle");
EXPECT_EQ(signs[3].text(), "Harrisburg");
} else {
FAIL() << "US 11/To I 81/Carlisle/Harrisburg failed to be parsed.";
}
signs.clear();
node.set_exit_to_index(osmdata.node_names.index("US 11;Toward I 81;Carlisle;Harrisburg"));
has_guide = GraphBuilder::CreateSignInfoList(node, way, pronunciationMap, langMap, osmdata,
default_languages, linguistic_node, signs, linguistics,
fork, forward, true, false);
EXPECT_FALSE(has_guide) << "Exits should not be Guides";
if (signs.size() == 4) {
for (auto& exitsign : signs) {
EXPECT_EQ(exitsign.type(), Sign::Type::kExitToward)
<< "US 11;Toward I 81;Carlisle;Harrisburg types are not all Toward";
}
EXPECT_EQ(signs[0].text(), "US 11");
EXPECT_EQ(signs[1].text(), "I 81");
EXPECT_EQ(signs[2].text(), "Carlisle");
EXPECT_EQ(signs[3].text(), "Harrisburg");
} else {
FAIL() << "US 11;Toward I 81;Carlisle;Harrisburg failed to be parsed.";
}
signs.clear();
node.set_exit_to_index(osmdata.node_names.index("I 95 To I 695"));
has_guide = GraphBuilder::CreateSignInfoList(node, way, pronunciationMap, langMap, osmdata,
default_languages, linguistic_node, signs, linguistics,
fork, forward, true, false);
EXPECT_FALSE(has_guide) << "Exits should not be Guides";
if (signs.size() == 2) {
EXPECT_EQ(signs[0].type(), Sign::Type::kExitBranch) << "I 95 should be a branch.";
EXPECT_EQ(signs[1].type(), Sign::Type::kExitToward) << "I 695 should be a toward.";
EXPECT_EQ(signs[0].text(), "I 95");
EXPECT_EQ(signs[1].text(), "I 695");
} else {
FAIL() << "I 95 To I 695 failed to be parsed.";
}
signs.clear();
node.set_exit_to_index(osmdata.node_names.index("I 495 Toward I 270"));
has_guide = GraphBuilder::CreateSignInfoList(node, way, pronunciationMap, langMap, osmdata,
default_languages, linguistic_node, signs, linguistics,
fork, forward, true, false);
EXPECT_FALSE(has_guide) << "Exits should not be Guides";
if (signs.size() == 2) {
EXPECT_EQ(signs[0].type(), Sign::Type::kExitBranch) << "I 495 should be a branch.";
EXPECT_EQ(signs[1].type(), Sign::Type::kExitToward) << "I 270 should be a toward.";
EXPECT_EQ(signs[0].text(), "I 495");
EXPECT_EQ(signs[1].text(), "I 270");
} else {
FAIL() << "I 495 Toward I 270 failed to be parsed.";
}
signs.clear();
node.set_exit_to_index(
osmdata.node_names.index("I 495 Toward I 270 To I 95")); // default to toward. Punt on parsing.
has_guide = GraphBuilder::CreateSignInfoList(node, way, pronunciationMap, langMap, osmdata,
default_languages, linguistic_node, signs, linguistics,
fork, forward, true, false);
EXPECT_FALSE(has_guide) << "Exits should not be Guides";
if (signs.size() == 1) {
EXPECT_EQ(signs[0].type(), Sign::Type::kExitToward)
<< "I 495 Toward I 270 To I 95 should be a toward.";
EXPECT_EQ(signs[0].text(), "I 495 Toward I 270 To I 95")
<< "Exitsign text is bad for I 495 Toward I 270 To I 95";
} else {
FAIL() << "I 495 Toward I 270 To I 95 failed to be parsed.";
}
// Add a ref branch sign
signs.clear();
auto index = osmdata.name_offset_map.index("I 495 North");
way.set_destination_ref_index(index);
has_guide = GraphBuilder::CreateSignInfoList(node, way, pronunciationMap, langMap, osmdata,
default_languages, linguistic_node, signs, linguistics,
fork, forward, true, false);
EXPECT_FALSE(has_guide) << "Exits should not be Guides";
if (signs.size() == 1) {
EXPECT_EQ(signs[0].type(), Sign::Type::kExitBranch) << "I 495 North should be a branch.";
EXPECT_TRUE(signs[0].is_route_num()) << "I 495 North should be flagged as a route num";
EXPECT_EQ(signs[0].text(), "I 495 North")
<< "Exitsign text is bad for I 495 North destination ref";
} else {
FAIL() << "destination ref I 495 North failed to create exist sign.";
}
signs.clear();
index = osmdata.name_offset_map.index("I 495 North");
way.set_destination_ref_index(index);
has_guide = GraphBuilder::CreateSignInfoList(node, way, pronunciationMap, langMap, osmdata,
default_languages, linguistic_node, signs, linguistics,
fork, forward, false, true);
EXPECT_TRUE(has_guide) << "Guides should not be Exits";
if (signs.size() == 1) {
EXPECT_EQ(signs[0].type(), Sign::Type::kGuideBranch) << "I 495 North should be a branch.";
EXPECT_TRUE(signs[0].is_route_num()) << "I 495 North should be flagged as a route num";
EXPECT_EQ(signs[0].text(), "I 495 North")
<< "Exitsign text is bad for I 495 North destination ref";
} else {
FAIL() << "destination ref I 495 North failed to create exist sign.";
}
// Add a ref toward sign
OSMWay way2{};
signs.clear();
auto index2 = osmdata.name_offset_map.index("I 695 North");
way2.set_destination_ref_to_index(index2);
has_guide = GraphBuilder::CreateSignInfoList(node, way2, pronunciationMap, langMap, osmdata,
default_languages, linguistic_node, signs, linguistics,
fork, forward, true, false);
EXPECT_FALSE(has_guide) << "Exits should not be Guides";
if (signs.size() == 1) {
EXPECT_EQ(signs[0].type(), Sign::Type::kExitToward) << "I 695 North should be a toward.";
EXPECT_TRUE(signs[0].is_route_num()) << "I 695 North should be flagged as a route num";
EXPECT_EQ(signs[0].text(), "I 695 North")
<< "Exitsign text is bad for I 695 North destination to ref";
} else {
FAIL() << "destination ref I 695 North failed to create exist sign.";
}
// Add a ref toward guide sign
OSMWay way3{};
signs.clear();
auto index3 = osmdata.name_offset_map.index("I 695 North");
way3.set_destination_ref_to_index(index3);
has_guide = GraphBuilder::CreateSignInfoList(node, way2, pronunciationMap, langMap, osmdata,
default_languages, linguistic_node, signs, linguistics,
fork, forward, false, true);
EXPECT_TRUE(has_guide) << "Guides should not be Exits";
if (signs.size() == 1) {
EXPECT_EQ(signs[0].type(), Sign::Type::kGuideToward) << "I 695 North should be a toward.";
EXPECT_TRUE(signs[0].is_route_num()) << "I 695 North should be flagged as a route num";
EXPECT_EQ(signs[0].text(), "I 695 North")
<< "Exitsign text is bad for I 695 North destination to ref";
} else {
FAIL() << "destination ref I 695 North failed to create exist sign.";
}
// Add a ref toward guide sign and we should not add a exit number or exit name. note: using
// exit_node
signs.clear();
has_guide = GraphBuilder::CreateSignInfoList(exit_node, way2, pronunciationMap, langMap, osmdata,
default_languages, linguistic_node, signs, linguistics,
fork, forward, false, true);
EXPECT_TRUE(has_guide) << "Guides should not be Exits";
if (signs.size() == 1) {
EXPECT_EQ(signs[0].type(), Sign::Type::kGuideToward)
<< "I 695 North should be a toward. No exit 5 should exist.";
EXPECT_TRUE(signs[0].is_route_num()) << "I 695 North should be flagged as a route num";
EXPECT_EQ(signs[0].text(), "I 695 North")
<< "Exitsign text is bad for I 695 North destination to ref";
} else {
FAIL() << "destination ref I 695 North failed to create exist sign. No exit 5 should exist.";
}
filesystem::remove(linguistic_node_file);
}
} // namespace
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}