Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cross_routing_tests.cpp « routing_tests « routing - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0b5e643ef38ee4fa39ea36d3f815ebe4dd46f86 (plain)
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
#include "testing/testing.hpp"

#include "routing/cross_mwm_road_graph.hpp"
#include "routing/cross_mwm_router.hpp"
#include "routing/cross_routing_context.hpp"

#include "coding/reader.hpp"
#include "coding/writer.hpp"

using namespace routing;

namespace
{
// Graph to convertions.
UNIT_TEST(TestCrossRouteConverter)
{
  Index::MwmId aMap, bMap;
  vector<BorderCross> graphCrosses;
  CrossNode const a(1, aMap, {0, 0}), b(2, aMap, {2, 2});
  CrossNode const c(3, bMap, {3, 3}), d(3, bMap, {4, 4});
  graphCrosses.emplace_back(a, b);
  graphCrosses.emplace_back(b, c);
  graphCrosses.emplace_back(c, d);
  FeatureGraphNode startGraphNode;
  startGraphNode.node.forward_node_id = 5;
  startGraphNode.mwmId = aMap;
  FeatureGraphNode finalGraphNode;
  finalGraphNode.node.reverse_node_id = 6;
  finalGraphNode.mwmId = bMap;
  TCheckedPath route;
  ConvertToSingleRouterTasks(graphCrosses, startGraphNode, finalGraphNode, route);
  TEST_EQUAL(route.size(), 2, ("We have 2 maps aMap and bMap."));
  TEST_EQUAL(route.front().startNode.node, startGraphNode.node,
             ("Start node must be replaced by origin."));
  TEST_EQUAL(route.back().finalNode.node, finalGraphNode.node,
             ("End node must be replaced by origin."));
}

// Cross routing context tests.
UNIT_TEST(TestContextSerialization)
{
  routing::CrossRoutingContextWriter context;
  routing::CrossRoutingContextReader newContext;

  context.AddIngoingNode(1, ms::LatLon::Zero());
  context.AddIngoingNode(2, ms::LatLon::Zero());
  context.AddOutgoingNode(3, "foo", ms::LatLon::Zero());
  context.AddOutgoingNode(4, "bar", ms::LatLon::Zero());
  context.ReserveAdjacencyMatrix();

  vector<char> buffer;
  MemWriter<vector<char> > writer(buffer);
  context.Save(writer);
  TEST_GREATER(buffer.size(), 5, ("Context serializer make some data"));

  MemReader reader(buffer.data(), buffer.size());
  newContext.Load(reader);
  vector<IngoingCrossNode> ingoingNodes;
  newContext.ForEachIngoingNode([&ingoingNodes](IngoingCrossNode const & node)
                                {
                                  ingoingNodes.push_back(node);
                                });
  TEST_EQUAL(ingoingNodes.size(), 2, ());
  TEST_EQUAL(ingoingNodes[0].m_nodeId, 1, ());
  TEST_EQUAL(ingoingNodes[1].m_nodeId, 2, ());

  vector<OutgoingCrossNode> outgoingNodes;
  newContext.ForEachOutgoingNode([&outgoingNodes](OutgoingCrossNode const & node)
                                 {
                                   outgoingNodes.push_back(node);
                                 });
  TEST_EQUAL(outgoingNodes.size(), 2, ());
  TEST_EQUAL(outgoingNodes[0].m_nodeId, 3, ());
  TEST_EQUAL(newContext.GetOutgoingMwmName(outgoingNodes[0]), string("foo"), ());
  TEST_EQUAL(outgoingNodes[1].m_nodeId, 4, ());
  TEST_EQUAL(newContext.GetOutgoingMwmName(outgoingNodes[1]), string("bar"), ());
}

UNIT_TEST(TestAdjacencyMatrix)
{
  routing::CrossRoutingContextWriter context;
  routing::CrossRoutingContextReader newContext;

  context.AddIngoingNode(1, ms::LatLon::Zero());
  context.AddIngoingNode(2, ms::LatLon::Zero());
  context.AddIngoingNode(3, ms::LatLon::Zero());
  context.AddOutgoingNode(4, "foo", ms::LatLon::Zero());
  context.ReserveAdjacencyMatrix();
  {
    auto ins = context.GetIngoingIterators();
    auto outs = context.GetOutgoingIterators();
    context.SetAdjacencyCost(ins.first, outs.first, 5);
    context.SetAdjacencyCost(ins.first + 1, outs.first, 9);
  }

  vector<char> buffer;
  MemWriter<vector<char> > writer(buffer);
  context.Save(writer);
  TEST_GREATER(buffer.size(), 5, ("Context serializer make some data"));

  MemReader reader(buffer.data(), buffer.size());
  newContext.Load(reader);
  vector<IngoingCrossNode> ingoingNodes;
  newContext.ForEachIngoingNode([&ingoingNodes](IngoingCrossNode const & node)
                                {
                                  ingoingNodes.push_back(node);
                                });
  vector<OutgoingCrossNode> outgoingNodes;
  newContext.ForEachOutgoingNode([&outgoingNodes](OutgoingCrossNode const & node)
                                 {
                                   outgoingNodes.push_back(node);
                                 });
  TEST_EQUAL(newContext.GetAdjacencyCost(ingoingNodes[0], outgoingNodes[0]), 5, ());
  TEST_EQUAL(newContext.GetAdjacencyCost(ingoingNodes[1], outgoingNodes[0]), 9, ());
  TEST_EQUAL(newContext.GetAdjacencyCost(ingoingNodes[2], outgoingNodes[0]),
             routing::kInvalidContextEdgeWeight, ("Default cost"));
}

UNIT_TEST(TestFindingByPoint)
{
  routing::CrossRoutingContextWriter context;
  routing::CrossRoutingContextReader newContext;

  ms::LatLon p1(1., 1.), p2(5., 5.), p3(10., 1.), p4(20., 1.);

  context.AddIngoingNode(1, ms::LatLon::Zero());
  context.AddIngoingNode(2, p1);
  context.AddIngoingNode(3, p2);
  context.AddOutgoingNode(4, "foo", ms::LatLon::Zero());
  context.AddIngoingNode(5, p3);
  context.AddIngoingNode(6, p3);
  context.ReserveAdjacencyMatrix();

  vector<char> buffer;
  MemWriter<vector<char> > writer(buffer);
  context.Save(writer);
  TEST_GREATER(buffer.size(), 5, ("Context serializer make some data"));

  MemReader reader(buffer.data(), buffer.size());
  newContext.Load(reader);
  vector<IngoingCrossNode> node;
  auto fn = [&node](IngoingCrossNode const & nd) {node.push_back(nd);};
  TEST(newContext.ForEachIngoingNodeNearPoint(p1, fn), ());
  TEST_EQUAL(node.size(), 1, ());
  TEST_EQUAL(node[0].m_nodeId, 2, ());
  node.clear();
  TEST(newContext.ForEachIngoingNodeNearPoint(p2, fn), ());
  TEST_EQUAL(node.size(), 1, ());
  TEST_EQUAL(node[0].m_nodeId, 3, ());
  node.clear();
  TEST(!newContext.ForEachIngoingNodeNearPoint(p4, fn), ());
  node.clear();
  TEST(newContext.ForEachIngoingNodeNearPoint(p3, fn), ());
  TEST_EQUAL(node.size(), 2, ());
  TEST_EQUAL(node[0].m_nodeId, 5, ());
  TEST_EQUAL(node[1].m_nodeId, 6, ());
}
}  // namespace