Add tests

This commit is contained in:
tatiana-kondakova 2017-07-25 14:49:47 +03:00 committed by Добрый Ээх
parent 845e41699a
commit 7f90c748bb
3 changed files with 29 additions and 4 deletions

View file

@ -11,15 +11,17 @@
namespace
{
routing::VehicleModel::InitListT const s_testLimits = {
{{"highway", "trunk"}, 150},
{{"highway", "primary"}, 120},
{{"highway", "secondary"}, 80},
{{"highway", "residential"}, 50},
{{"highway", "trunk"}, 150, true},
{{"highway", "primary"}, 120, true},
{{"highway", "secondary"}, 80, true},
{{"highway", "residential"}, 50, true},
{{"highway", "service"}, 50, false},
};
class TestVehicleModel : public routing::VehicleModel
{
friend void CheckOneWay(initializer_list<uint32_t> const & types, bool expectedValue);
friend void CheckTransitAllowed(initializer_list<uint32_t> const & types, bool expectedValue);
friend void CheckSpeed(initializer_list<uint32_t> const & types, double expectedSpeed);
public:
@ -57,6 +59,16 @@ void CheckOneWay(initializer_list<uint32_t> const & types, bool expectedValue)
TEST_EQUAL(vehicleModel.HasOneWayType(h), expectedValue, ());
}
void CheckTransitAllowed(initializer_list<uint32_t> const & types, bool expectedValue)
{
TestVehicleModel vehicleModel;
feature::TypesHolder h;
for (uint32_t t : types)
h.Add(t);
TEST_EQUAL(vehicleModel.HasTransitType(h), expectedValue, ());
}
} // namespace
UNIT_TEST(VehicleModel_MaxSpeed)
@ -114,3 +126,10 @@ UNIT_TEST(VehicleModel_DifferentSpeeds)
CheckSpeed({typePrimary, typeOneway, typeSecondary}, 80.0);
CheckOneWay({typePrimary, typeOneway, typeSecondary}, true);
}
UNIT_TEST(VehicleModel_TransitAllowed)
{
CheckTransitAllowed({GetType("highway", "secondary")}, true);
CheckTransitAllowed({GetType("highway", "primary")}, true);
CheckTransitAllowed({GetType("highway", "service")}, false);
}

View file

@ -114,7 +114,11 @@ bool VehicleModel::IsRoad(FeatureType const & f) const
bool VehicleModel::IsTransitAllowed(FeatureType const & f) const
{
feature::TypesHolder const types(f);
return HasTransitType(types);
}
bool VehicleModel::HasTransitType(feature::TypesHolder const & types) const
{
for (uint32_t t : types)
{
uint32_t const type = ftypes::BaseChecker::PrepareToMatch(t, 2);

View file

@ -113,6 +113,8 @@ protected:
/// may be considered as features with forward geometry.
bool HasOneWayType(feature::TypesHolder const & types) const;
bool HasTransitType(feature::TypesHolder const & types) const;
double GetMinTypeSpeed(feature::TypesHolder const & types) const;
double m_maxSpeedKMpH;