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

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

#include "routing/routing_tests/road_graph_builder.hpp"

#include "routing/road_graph.hpp"
#include "routing/nearest_edge_finder.hpp"

#include "routing_common/maxspeed_conversion.hpp"

#include "base/checked_cast.hpp"

using namespace routing;
using namespace routing_test;
using namespace std;

void TestNearestOnMock1(m2::PointD const & point, size_t const candidatesCount,
                        vector<pair<Edge, Junction>> const & expected)
{
  unique_ptr<RoadGraphMockSource> graph(new RoadGraphMockSource());
  InitRoadGraphMockSourceWithTest1(*graph);

  NearestEdgeFinder finder(point, nullptr /* isEdgeProjGood */);
  for (size_t i = 0; i < graph->GetRoadCount(); ++i)
  {
    FeatureID const featureId = MakeTestFeatureID(base::checked_cast<uint32_t>(i));
    auto const & roadInfo =
        graph->GetRoadInfo(featureId, {true /* forward */, false /* in city */, Maxspeed()});
    finder.AddInformationSource(IRoadGraph::FullRoadInfo(featureId, roadInfo));
  }

  vector<pair<Edge, Junction>> result;
  TEST(finder.HasCandidates(), ());
  finder.MakeResult(result, candidatesCount);

  TEST_EQUAL(result, expected, ());
}

UNIT_TEST(StarterPosAtBorder_Mock1Graph)
{
  vector<pair<Edge, Junction>> const expected = {
      make_pair(Edge::MakeReal(MakeTestFeatureID(0), true /* forward */, 0,
                               MakeJunctionForTesting(m2::PointD(0, 0)),
                               MakeJunctionForTesting(m2::PointD(5, 0))),
                MakeJunctionForTesting(m2::PointD(0, 0)))};
  TestNearestOnMock1(m2::PointD(0, 0), 1, expected);
}

UNIT_TEST(MiddleEdgeTest_Mock1Graph)
{
  vector<pair<Edge, Junction>> const expected = {
      make_pair(Edge::MakeReal(MakeTestFeatureID(0), true /* forward */, 0,
                               MakeJunctionForTesting(m2::PointD(0, 0)),
                               MakeJunctionForTesting(m2::PointD(5, 0))),
                MakeJunctionForTesting(m2::PointD(3, 0)))};
  TestNearestOnMock1(m2::PointD(3, 3), 1, expected);
}

UNIT_TEST(MiddleSegmentTest_Mock1Graph)
{
  vector<pair<Edge, Junction>> const expected = {
      make_pair(Edge::MakeReal(MakeTestFeatureID(0), true /* forward */, 2,
                               MakeJunctionForTesting(m2::PointD(10, 0)),
                               MakeJunctionForTesting(m2::PointD(15, 0))),
                MakeJunctionForTesting(m2::PointD(12.5, 0))),
      make_pair(Edge::MakeReal(MakeTestFeatureID(0), false /* forward */, 2,
                               MakeJunctionForTesting(m2::PointD(15, 0)),
                               MakeJunctionForTesting(m2::PointD(10, 0))),
                MakeJunctionForTesting(m2::PointD(12.5, 0)))};
  TestNearestOnMock1(m2::PointD(12.5, 2.5), 2, expected);
}