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
|
#include "testing/testing.hpp"
#include "routing/road_graph.hpp"
#include "routing/routing_tests/road_graph_builder.hpp"
#include "std/algorithm.hpp"
namespace routing_test
{
using namespace routing;
UNIT_TEST(RoadGraph_NearestEdges)
{
// ^ 1st road
// o
// |
// |
// o
// |
// | 0th road
// o--o--x--o--o >
// |
// |
// o
// |
// |
// o
//
// Two roads are intersecting in (0, 0).
RoadGraphMockSource graph;
{
IRoadGraph::RoadInfo ri0;
ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(-2, 0)));
ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(-1, 0)));
ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, 0)));
ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(1, 0)));
ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(2, 0)));
ri0.m_speedKMPH = 5;
ri0.m_bidirectional = true;
IRoadGraph::RoadInfo ri1;
ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, -2)));
ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, -1)));
ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, 0)));
ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, 1)));
ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, 2)));
ri1.m_speedKMPH = 5;
ri1.m_bidirectional = true;
graph.AddRoad(move(ri0));
graph.AddRoad(move(ri1));
}
// We are standing at x junction.
Junction const crossPos = MakeJunctionForTesting(m2::PointD(0, 0));
// Expected outgoing edges.
IRoadGraph::TEdgeVector expectedOutgoing = {
Edge(MakeTestFeatureID(0) /* first road */, false /* forward */, 1 /* segId */,
MakeJunctionForTesting(m2::PointD(0, 0)), MakeJunctionForTesting(m2::PointD(-1, 0))),
Edge(MakeTestFeatureID(0) /* first road */, true /* forward */, 2 /* segId */,
MakeJunctionForTesting(m2::PointD(0, 0)), MakeJunctionForTesting(m2::PointD(1, 0))),
Edge(MakeTestFeatureID(1) /* second road */, false /* forward */, 1 /* segId */,
MakeJunctionForTesting(m2::PointD(0, 0)), MakeJunctionForTesting(m2::PointD(0, -1))),
Edge(MakeTestFeatureID(1) /* second road */, true /* forward */, 2 /* segId */,
MakeJunctionForTesting(m2::PointD(0, 0)), MakeJunctionForTesting(m2::PointD(0, 1))),
};
sort(expectedOutgoing.begin(), expectedOutgoing.end());
// Expected ingoing edges.
IRoadGraph::TEdgeVector expectedIngoing = {
Edge(MakeTestFeatureID(0) /* first road */, true /* forward */, 1 /* segId */,
MakeJunctionForTesting(m2::PointD(-1, 0)), MakeJunctionForTesting(m2::PointD(0, 0))),
Edge(MakeTestFeatureID(0) /* first road */, false /* forward */, 2 /* segId */,
MakeJunctionForTesting(m2::PointD(1, 0)), MakeJunctionForTesting(m2::PointD(0, 0))),
Edge(MakeTestFeatureID(1) /* second road */, true /* forward */, 1 /* segId */,
MakeJunctionForTesting(m2::PointD(0, -1)), MakeJunctionForTesting(m2::PointD(0, 0))),
Edge(MakeTestFeatureID(1) /* second road */, false /* forward */, 2 /* segId */,
MakeJunctionForTesting(m2::PointD(0, 1)), MakeJunctionForTesting(m2::PointD(0, 0))),
};
sort(expectedIngoing.begin(), expectedIngoing.end());
// Check outgoing edges.
IRoadGraph::TEdgeVector actualOutgoing;
graph.GetOutgoingEdges(crossPos, actualOutgoing);
sort(actualOutgoing.begin(), actualOutgoing.end());
TEST_EQUAL(expectedOutgoing, actualOutgoing, ());
// Check ingoing edges.
IRoadGraph::TEdgeVector actualIngoing;
graph.GetIngoingEdges(crossPos, actualIngoing);
sort(actualIngoing.begin(), actualIngoing.end());
TEST_EQUAL(expectedIngoing, actualIngoing, ());
}
} // namespace routing_test
|