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

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

#include "routing/vehicle_model.hpp"

#include "indexer/classificator.hpp"
#include "indexer/classificator_loader.hpp"
#include "indexer/feature.hpp"

#include "base/macros.hpp"


namespace
{

routing::VehicleModel::InitListT const s_testLimits = {
    {{"highway", "trunk"}, 150},
    {{"highway", "primary"}, 120},
    {{"highway", "secondary"}, 80},
    {{"highway", "residential"}, 50},
};

class TestVehicleModel : public routing::VehicleModel
{
  friend void CheckOneWay(initializer_list<uint32_t> const & types, bool expectedValue);
  friend void CheckSpeed(initializer_list<uint32_t> const & types, double expectedSpeed);

public:
  TestVehicleModel() : VehicleModel(classif(), s_testLimits) {}
};

uint32_t GetType(char const * s0, char const * s1 = 0, char const * s2 = 0)
{
  char const * const t[] = {s0, s1, s2};
  size_t const size = (s0 != 0) + size_t(s1 != 0) + size_t(s2 != 0);
  return classif().GetTypeByPath(vector<string>(t, t + size));
}

uint32_t GetOnewayType()
{
  return GetType("hwtag", "oneway");
}

void CheckSpeed(initializer_list<uint32_t> const & types, double expectedSpeed)
{
  TestVehicleModel vehicleModel;
  feature::TypesHolder h;
  for (uint32_t t : types)
    h.Add(t);

  TEST_EQUAL(vehicleModel.GetMinTypeSpeed(h), expectedSpeed, ());
}

void CheckOneWay(initializer_list<uint32_t> const & types, bool expectedValue)
{
  TestVehicleModel vehicleModel;
  feature::TypesHolder h;
  for (uint32_t t : types)
    h.Add(t);

  TEST_EQUAL(vehicleModel.HasOneWayType(h), expectedValue, ());
}
}  // namespace

UNIT_TEST(VehicleModel_MaxSpeed)
{
  classificator::Load();

  TestVehicleModel vehicleModel;
  TEST_EQUAL(vehicleModel.GetMaxSpeed(), 150, ());
}

UNIT_TEST(VehicleModel_Speed)
{
  CheckSpeed({GetType("highway", "secondary", "bridge")}, 80.0);
  CheckSpeed({GetType("highway", "secondary", "tunnel")}, 80.0);
  CheckSpeed({GetType("highway", "secondary")}, 80.0);

  CheckSpeed({GetType("highway", "trunk")}, 150.0);
  CheckSpeed({GetType("highway", "primary")}, 120.0);
  CheckSpeed({GetType("highway", "residential")}, 50.0);
}

UNIT_TEST(VehicleModel_Speed_MultiTypes)
{
  uint32_t const typeTunnel = GetType("highway", "secondary", "tunnel");
  uint32_t const typeSecondary = GetType("highway", "secondary");
  uint32_t const typeHighway = GetType("highway");

  CheckSpeed({typeTunnel, typeSecondary}, 80.0);
  CheckSpeed({typeTunnel, typeHighway}, 80.0);
  CheckSpeed({typeHighway, typeTunnel}, 80.0);
}

UNIT_TEST(VehicleModel_OneWay)
{
  uint32_t const typeBridge = GetType("highway", "secondary", "bridge");
  uint32_t const typeOneway = GetOnewayType();

  CheckSpeed({typeBridge, typeOneway}, 80.0);
  CheckOneWay({typeBridge, typeOneway}, true);
  CheckSpeed({typeOneway, typeBridge}, 80.0);
  CheckOneWay({typeOneway, typeBridge}, true);

  CheckOneWay({typeOneway}, true);
}

UNIT_TEST(VehicleModel_DifferentSpeeds)
{
  uint32_t const typeSecondary = GetType("highway", "secondary");
  uint32_t const typePrimary = GetType("highway", "primary");
  uint32_t const typeOneway = GetOnewayType();

  CheckSpeed({typeSecondary, typePrimary}, 80.0);
  CheckSpeed({typePrimary, typeSecondary}, 80.0);

  CheckSpeed({typePrimary, typeOneway, typeSecondary}, 80.0);
  CheckOneWay({typePrimary, typeOneway, typeSecondary}, true);
}