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
|
#include "testing/testing.hpp"
#include "map/routing_mark.hpp"
#include "routing/router.hpp"
#include "routing/routing_options.hpp"
#include <initializer_list>
namespace road_warning_tests
{
namespace
{
using routing::RouterType;
using routing::RoutingOptions;
using Road = RoutingOptions::Road;
RoutingOptions MakeOptions(std::initializer_list<Road> const roads)
{
RoutingOptions options;
for (auto const r : roads)
options.Add(r);
return options;
}
} // namespace
UNIT_TEST(RoadWarning_IsWarningShownFor)
{
using enum RoadWarningMarkType;
// Toll / Dirty / lift gate: car only.
for (auto const t : {Toll, Dirty, LiftGate})
{
TEST(IsWarningShownFor(t, RouterType::Vehicle), (t));
TEST(!IsWarningShownFor(t, RouterType::Pedestrian), (t));
TEST(!IsWarningShownFor(t, RouterType::Bicycle), (t));
}
// Steps: pedestrian / bicycle only.
TEST(IsWarningShownFor(Steps, RouterType::Pedestrian), ());
TEST(IsWarningShownFor(Steps, RouterType::Bicycle), ());
TEST(!IsWarningShownFor(Steps, RouterType::Vehicle), ());
// Ferry / gate: car, pedestrian and bicycle.
for (auto const r : {RouterType::Vehicle, RouterType::Pedestrian, RouterType::Bicycle})
{
TEST(IsWarningShownFor(Ferry, r), (r));
TEST(IsWarningShownFor(Gate, r), (r));
}
// Transit / ruler: no warnings at all.
for (auto const r : {RouterType::Transit, RouterType::Ruler})
for (auto const t : {Toll, Ferry, Dirty, Steps, Gate, LiftGate})
TEST(!IsWarningShownFor(t, r), (t, r));
}
UNIT_TEST(RoadWarning_ChooseRoadWarning)
{
using enum RoadWarningMarkType;
// No road options -> nothing to warn about.
TEST_EQUAL(ChooseRoadWarning(MakeOptions({}), RouterType::Vehicle), Count, ());
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Motorway, Road::Usual}), RouterType::Vehicle), Count, ());
// Car priority: Toll > Ferry > Dirty.
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Toll, Road::Ferry, Road::Dirty}), RouterType::Vehicle), Toll, ());
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Ferry, Road::Dirty}), RouterType::Vehicle), Ferry, ());
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Dirty}), RouterType::Vehicle), Dirty, ());
// Regression: an unpaved staircase carries {Dirty, Steps} (the generator tags steps having a
// surface/smoothness with an unpaved psurface). Filtering by router type first means a pedestrian/
// cyclist still gets the Steps warning instead of it being dropped because Dirty is checked first.
auto const unpavedSteps = MakeOptions({Road::Dirty, Road::Steps});
TEST_EQUAL(ChooseRoadWarning(unpavedSteps, RouterType::Pedestrian), Steps, ());
TEST_EQUAL(ChooseRoadWarning(unpavedSteps, RouterType::Bicycle), Steps, ());
// Steps are not shown to cars; only Dirty remains there (steps don't occur on car routes anyway).
TEST_EQUAL(ChooseRoadWarning(unpavedSteps, RouterType::Vehicle), Dirty, ());
// Bare steps: shown to pedestrian/bicycle, nothing for car.
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Steps}), RouterType::Pedestrian), Steps, ());
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Steps}), RouterType::Bicycle), Steps, ());
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Steps}), RouterType::Vehicle), Count, ());
// Toll / Dirty are car-only.
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Toll}), RouterType::Pedestrian), Count, ());
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Dirty}), RouterType::Pedestrian), Count, ());
// Ferry is shown to everyone.
for (auto const r : {RouterType::Vehicle, RouterType::Pedestrian, RouterType::Bicycle})
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Ferry}), r), Ferry, (r));
// Transit / ruler never warn.
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Ferry, Road::Steps}), RouterType::Transit), Count, ());
TEST_EQUAL(ChooseRoadWarning(MakeOptions({Road::Dirty}), RouterType::Ruler), Count, ());
}
UNIT_TEST(RoadWarning_IsAvoidableRoadWarning)
{
using enum RoadWarningMarkType;
// Backed by a car driving-option toggle.
TEST(IsAvoidableRoadWarning(Toll), ());
TEST(IsAvoidableRoadWarning(Ferry), ());
TEST(IsAvoidableRoadWarning(Dirty), ());
// No avoid option -> must not surface the "driving options" affordance.
TEST(!IsAvoidableRoadWarning(Steps), ());
TEST(!IsAvoidableRoadWarning(Gate), ());
TEST(!IsAvoidableRoadWarning(LiftGate), ());
}
} // namespace road_warning_tests
|