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

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2018-12-06 15:06:18 +0300
committerVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2018-12-07 11:05:00 +0300
commit33a1eab9118528ff63d1eb94afa7eb0f3d558bc8 (patch)
tree5d9e5c2d2f970fab25dd7de2abe972ab301b8baa /routing_common
parent3c57cf21e464266f83d18eaeaece38105db14760 (diff)
[routing] Adding unit tests on maxspeed factors.
Diffstat (limited to 'routing_common')
-rw-r--r--routing_common/routing_common_tests/vehicle_model_test.cpp113
1 files changed, 84 insertions, 29 deletions
diff --git a/routing_common/routing_common_tests/vehicle_model_test.cpp b/routing_common/routing_common_tests/vehicle_model_test.cpp
index afd10d077b..670c1cdd64 100644
--- a/routing_common/routing_common_tests/vehicle_model_test.cpp
+++ b/routing_common/routing_common_tests/vehicle_model_test.cpp
@@ -1,31 +1,40 @@
#include "testing/testing.hpp"
+#include "routing_common/maxspeed_conversion.hpp"
#include "routing_common/vehicle_model.hpp"
#include "indexer/classificator.hpp"
#include "indexer/classificator_loader.hpp"
#include "indexer/feature.hpp"
+#include "platform/measurement_utils.hpp"
+
#include "base/macros.hpp"
+#include <cstdint>
+
+using namespace routing;
using namespace std;
+using MaxspeedFactor = VehicleModel::MaxspeedFactor;
+
namespace
{
using SpeedKMpH = routing::VehicleModel::SpeedKMpH;
using InOutCitySpeedKMpH = routing::VehicleModel::InOutCitySpeedKMpH;
InOutCitySpeedKMpH const speedSecondaryExpected = {
- {80.0 /* weight */, 70.0 /* eta */} /* in city */,
- {80.0 /* weight */, 70.0 /* eta */} /* out of city */};
+ SpeedKMpH(80.0 /* weight */, 70.0 /* eta */) /* in city */,
+ SpeedKMpH(80.0 /* weight */, 70.0 /* eta */) /* out of city */, MaxspeedFactor(1.0)};
routing::VehicleModel::LimitsInitList const s_testLimits = {
- // In city weight and eta speeds. Out of city weight and eta speeds.
- {{"highway", "trunk"}, {SpeedKMpH(100.0, 100.0), SpeedKMpH(150.0, 150.0)}, true},
- {{"highway", "primary"}, {SpeedKMpH(90.0, 90.0), SpeedKMpH(120.0, 120.0)}, true},
+ {{"highway", "trunk"}, {SpeedKMpH(100.0 /* weight */, 100.0 /* eta */) /* in city */,
+ SpeedKMpH(150.0 /* weight */, 150.0 /* eta */) /* out of city */,
+ MaxspeedFactor(1.0)}, true},
+ {{"highway", "primary"}, {SpeedKMpH(90.0, 90.0), SpeedKMpH(120.0, 120.0), MaxspeedFactor(1.0)}, true},
{{"highway", "secondary"}, speedSecondaryExpected, true},
- {{"highway", "residential"}, {SpeedKMpH(45.0, 55.0), SpeedKMpH(50.0, 60.0)}, true},
- {{"highway", "service"}, {SpeedKMpH(47.0, 36.0), SpeedKMpH(50.0, 40.0)}, false}};
+ {{"highway", "residential"}, {SpeedKMpH(45.0, 55.0), SpeedKMpH(50.0, 60.0), MaxspeedFactor(0.5)}, true},
+ {{"highway", "service"}, {SpeedKMpH(47.0, 36.0), SpeedKMpH(50.0, 40.0), MaxspeedFactor(1.0)}, false}};
routing::VehicleModel::SurfaceInitList const g_carSurface = {
{{"psurface", "paved_good"}, {0.8 /* weightFactor */, 0.9 /* etaFactor */}},
@@ -44,10 +53,13 @@ class TestVehicleModel : public routing::VehicleModel
{
friend void CheckOneWay(initializer_list<uint32_t> const & types, bool expectedValue);
friend void CheckPassThroughAllowed(initializer_list<uint32_t> const & types, bool expectedValue);
- friend void CheckSpeed(initializer_list<uint32_t> const & types, InOutCitySpeedKMpH const & expectedSpeed);
+ friend void CheckSpeedWithParams(initializer_list<uint32_t> const & types,
+ SpeedParams const & params, SpeedKMpH const & expectedSpeed);
-public:
- TestVehicleModel() : VehicleModel(classif(), s_testLimits, g_carSurface) {}
+ public : TestVehicleModel()
+ : VehicleModel(classif(), s_testLimits, g_carSurface)
+ {
+ }
// We are not going to use offroad routing in these tests.
double GetOffroadSpeed() const override { return 0.0; }
@@ -65,15 +77,23 @@ uint32_t GetOnewayType()
return GetType("hwtag", "oneway");
}
-void CheckSpeed(initializer_list<uint32_t> const & types, InOutCitySpeedKMpH const & expectedSpeed)
+void CheckSpeedWithParams(initializer_list<uint32_t> const & types, SpeedParams const & params,
+ SpeedKMpH const & expectedSpeed)
{
TestVehicleModel vehicleModel;
feature::TypesHolder h;
for (uint32_t t : types)
h.Add(t);
- TEST_EQUAL(vehicleModel.GetMinTypeSpeed(h, true /* in city */), expectedSpeed.m_inCity, ());
- TEST_EQUAL(vehicleModel.GetMinTypeSpeed(h, false /* in city */), expectedSpeed.m_outCity, ());
+ TEST_EQUAL(vehicleModel.GetTypeSpeed(h, params), expectedSpeed, ());
+}
+
+void CheckSpeed(initializer_list<uint32_t> const & types, InOutCitySpeedKMpH const & expectedSpeed)
+{
+ SpeedParams const inCity(true /* forward */, true /* in city */, Maxspeed());
+ CheckSpeedWithParams(types, inCity, expectedSpeed.m_inCity);
+ SpeedParams const outCity(true /* forward */, false /* in city */, Maxspeed());
+ CheckSpeedWithParams(types, outCity, expectedSpeed.m_outCity);
}
void CheckOneWay(initializer_list<uint32_t> const & types, bool expectedValue)
@@ -106,17 +126,19 @@ UNIT_CLASS_TEST(VehicleModelTest, VehicleModel_MaxSpeed)
UNIT_CLASS_TEST(VehicleModelTest, VehicleModel_Speed)
{
{
-
CheckSpeed({GetType("highway", "secondary", "bridge")}, speedSecondaryExpected);
CheckSpeed({GetType("highway", "secondary", "tunnel")}, speedSecondaryExpected);
CheckSpeed({GetType("highway", "secondary")}, speedSecondaryExpected);
}
CheckSpeed({GetType("highway", "trunk")},
- {{100.0 /* weight */, 100.0 /* eta */} /* in city */,
- {150.0 /* weight */, 150.0 /* eta */} /* out of city */});
- CheckSpeed({GetType("highway", "primary")}, {{90.0, 90.0}, {120.0, 120.0}});
- CheckSpeed({GetType("highway", "residential")}, {{45.0, 55.0}, {50.0, 60.0}});
+ {SpeedKMpH(100.0 /* weight */, 100.0 /* eta */) /* in city */,
+ SpeedKMpH(150.0 /* weight */, 150.0 /* eta */) /* out of city */,
+ MaxspeedFactor(1.0)});
+ CheckSpeed({GetType("highway", "primary")},
+ {SpeedKMpH(90.0, 90.0), SpeedKMpH(120.0, 120.0), MaxspeedFactor(1.0)});
+ CheckSpeed({GetType("highway", "residential")},
+ {SpeedKMpH(45.0, 55.0), SpeedKMpH(50.0, 60.0), MaxspeedFactor(1.0)});
}
UNIT_CLASS_TEST(VehicleModelTest, VehicleModel_Speed_MultiTypes)
@@ -150,9 +172,8 @@ UNIT_CLASS_TEST(VehicleModelTest, VehicleModel_DifferentSpeeds)
uint32_t const typeOneway = GetOnewayType();
CheckSpeed({typeSecondary, typePrimary}, speedSecondaryExpected);
- CheckSpeed({typePrimary, typeSecondary}, speedSecondaryExpected);
- CheckSpeed({typePrimary, typeOneway, typeSecondary}, speedSecondaryExpected);
+ CheckSpeed({typeSecondary, typePrimary, typeOneway}, speedSecondaryExpected);
CheckOneWay({typePrimary, typeOneway, typeSecondary}, true);
}
@@ -172,14 +193,48 @@ UNIT_CLASS_TEST(VehicleModelTest, VehicleModel_SpeedFactor)
uint32_t const unpavedGood = GetType("psurface", "unpaved_good");
uint32_t const unpavedBad = GetType("psurface", "unpaved_bad");
- CheckSpeed({secondary, pavedGood}, {{64.0 /* weight */, 63.0 /* eta */} /* in city */,
- {64.0 /* weight */, 63.0 /* eta */} /* out of city */});
- CheckSpeed({secondary, pavedBad}, {{32.0, 35.0}, {32.0, 35.0}});
- CheckSpeed({secondary, unpavedGood}, {{48.0, 56.0}, {48.0, 56.0}});
- CheckSpeed({secondary, unpavedBad}, {{16.0, 14.0}, {16.0, 14.0}});
+ CheckSpeed({secondary, pavedGood}, {SpeedKMpH(64.0 /* weight */, 63.0 /* eta */) /* in city */,
+ SpeedKMpH(64.0 /* weight */, 63.0 /* eta */) /* out of city */,
+ MaxspeedFactor(1.0)});
+ CheckSpeed({secondary, pavedBad}, {SpeedKMpH(32.0, 35.0), SpeedKMpH(32.0, 35.0), MaxspeedFactor(1.0)});
+ CheckSpeed({secondary, unpavedGood}, {SpeedKMpH(48.0, 56.0), SpeedKMpH(48.0, 56.0), MaxspeedFactor(1.0)});
+ CheckSpeed({secondary, unpavedBad}, {SpeedKMpH(16.0, 14.0), SpeedKMpH(16.0, 14.0), MaxspeedFactor(1.0)});
+
+ CheckSpeed({residential, pavedGood}, {SpeedKMpH(36.0, 49.5), SpeedKMpH(40.0, 54.0), MaxspeedFactor(1.0)});
+ CheckSpeed({residential, pavedBad}, {SpeedKMpH(18.0, 27.5), SpeedKMpH(20.0, 30.0), MaxspeedFactor(1.0)});
+ CheckSpeed({residential, unpavedGood}, {SpeedKMpH(27.0, 44.0), SpeedKMpH(30.0, 48.0), MaxspeedFactor(1.0)});
+ CheckSpeed({residential, unpavedBad}, {SpeedKMpH(9.0, 11.0), SpeedKMpH(10.0, 12.0), MaxspeedFactor(1.0)});
+}
+
+UNIT_CLASS_TEST(VehicleModelTest, VehicleModel_MaxspeedFactor)
+{
+ uint32_t const secondary = GetType("highway", "secondary");
+ uint32_t const residential = GetType("highway", "residential");
+ uint32_t const primary = GetType("highway", "primary");
+ uint32_t const pavedGood = GetType("psurface", "paved_good");
+ uint32_t const unpavedBad = GetType("psurface", "unpaved_bad");
- CheckSpeed({residential, pavedGood}, {{36.0, 49.5}, {40.0, 54.0}});
- CheckSpeed({residential, pavedBad}, {{18.0, 27.5}, {20.0, 30.0}});
- CheckSpeed({residential, unpavedGood}, {{27.0, 44.0}, {30.0, 48.0}});
- CheckSpeed({residential, unpavedBad}, {{9.0, 11.0}, {10.0, 12.0}});
+ Maxspeed const maxspeed90 =
+ Maxspeed(measurement_utils::Units::Metric, 90 /* forward speed */, kInvalidSpeed);
+ CheckSpeedWithParams({secondary, unpavedBad},
+ SpeedParams(true /* forward */, false /* in city */, maxspeed90),
+ SpeedKMpH(90.0));
+ CheckSpeedWithParams({primary, pavedGood},
+ SpeedParams(true /* forward */, false /* in city */, maxspeed90),
+ SpeedKMpH(90.0));
+
+ Maxspeed const maxspeed9070 =
+ Maxspeed(measurement_utils::Units::Metric, 90 /* forward speed */, 70);
+ CheckSpeedWithParams({primary, pavedGood},
+ SpeedParams(true /* forward */, false /* in city */, maxspeed9070),
+ SpeedKMpH(90.0));
+ CheckSpeedWithParams({primary, pavedGood},
+ SpeedParams(false /* forward */, false /* in city */, maxspeed9070),
+ SpeedKMpH(70.0));
+
+ Maxspeed const maxspeed60 =
+ Maxspeed(measurement_utils::Units::Metric, 60 /* forward speed */, kInvalidSpeed);
+ CheckSpeedWithParams({residential, pavedGood},
+ SpeedParams(true /* forward */, false /* in city */, maxspeed60),
+ SpeedKMpH(30.0));
}