From a4ffb95e499ede06efced7636773d51f9820ce17 Mon Sep 17 00:00:00 2001 From: kshalnev Date: Sat, 23 Jan 2016 11:03:10 +0300 Subject: [PATCH] [old map downloader] Fixed pedestrian rounting tests --- .../pedestrian_routing_tests.cpp | 85 ++++++++++++++----- 1 file changed, 62 insertions(+), 23 deletions(-) diff --git a/pedestrian_routing_tests/pedestrian_routing_tests.cpp b/pedestrian_routing_tests/pedestrian_routing_tests.cpp index 7b4e6c86f6..e815479620 100644 --- a/pedestrian_routing_tests/pedestrian_routing_tests.cpp +++ b/pedestrian_routing_tests/pedestrian_routing_tests.cpp @@ -9,21 +9,45 @@ #include "routing/pedestrian_model.hpp" #include "routing/router_delegate.hpp" +#include "storage/country_info_getter.hpp" + +#include "platform/platform.hpp" + #include "base/logging.hpp" #include "base/macros.hpp" #include "base/timer.hpp" +#include "std/set.hpp" #include "std/string.hpp" #include "std/utility.hpp" #include "std/vector.hpp" +#include "defines.hpp" + using platform::CountryFile; using platform::LocalCountryFile; namespace { -string const MAP_NAME = "UK_England"; +// Test preconditions: +// Files from the kMapFiles set with '.mwm' extension must be placed in ./omim/data folder + +set const kMapFiles = +{ + "UK_England_East Midlands", + "UK_England_East of England_Essex", + "UK_England_East of England_Norfolk", + "UK_England_Greater London", + "UK_England_North East England", + "UK_England_North West England", + "UK_England_South East_Brighton", + "UK_England_South East_Oxford", + "UK_England_South West England_Bristol", + "UK_England_South West England_Cornwall", + "UK_England_West Midlands", + "UK_England_Yorkshire and the Humber" +}; // Since for test purposes we compare routes lengths to check algorithms consistency, // we should use simplified pedestrian model, where all available edges have max speed @@ -58,21 +82,28 @@ private: shared_ptr const m_model; }; -unique_ptr CreatePedestrianAStarTestRouter(Index & index) +unique_ptr CreateCountryInfoGetter() { - auto UKGetter = [](m2::PointD const & /* point */){return "UK_England";}; + Platform & platform = GetPlatform(); + return unique_ptr(new storage::CountryInfoReader(platform.GetReader(PACKED_POLYGONS_MIGRATE_FILE), + platform.GetReader(COUNTRIES_MIGRATE_FILE))); +} + +unique_ptr CreatePedestrianAStarTestRouter(Index & index, storage::CountryInfoGetter & cig) +{ + auto fnUKGetter = [&](m2::PointD const & pt) { return cig.GetRegionFile(pt); }; unique_ptr vehicleModelFactory(new SimplifiedPedestrianModelFactory()); unique_ptr algorithm(new routing::AStarRoutingAlgorithm()); - unique_ptr router(new routing::RoadGraphRouter("test-astar-pedestrian", index, UKGetter, move(vehicleModelFactory), move(algorithm), nullptr)); + unique_ptr router(new routing::RoadGraphRouter("test-astar-pedestrian", index, fnUKGetter, move(vehicleModelFactory), move(algorithm), nullptr)); return router; } -unique_ptr CreatePedestrianAStarBidirectionalTestRouter(Index & index) +unique_ptr CreatePedestrianAStarBidirectionalTestRouter(Index & index, storage::CountryInfoGetter & cig) { - auto UKGetter = [](m2::PointD const & /* point */){return "UK_England";}; + auto fnUKGetter = [&](m2::PointD const & pt) { return cig.GetRegionFile(pt); }; unique_ptr vehicleModelFactory(new SimplifiedPedestrianModelFactory()); unique_ptr algorithm(new routing::AStarBidirectionalRoutingAlgorithm()); - unique_ptr router(new routing::RoadGraphRouter("test-astar-bidirectional-pedestrian", index, UKGetter, move(vehicleModelFactory), move(algorithm), nullptr)); + unique_ptr router(new routing::RoadGraphRouter("test-astar-bidirectional-pedestrian", index, fnUKGetter, move(vehicleModelFactory), move(algorithm), nullptr)); return router; } @@ -112,14 +143,16 @@ void TestRouter(routing::IRouter & router, m2::PointD const & startPos, m2::Poin void TestRouters(Index & index, m2::PointD const & startPos, m2::PointD const & finalPos) { + auto cig = CreateCountryInfoGetter(); + // find route by A*-bidirectional algorithm routing::Route routeFoundByAstarBidirectional(""); - unique_ptr router = CreatePedestrianAStarBidirectionalTestRouter(index); + unique_ptr router = CreatePedestrianAStarBidirectionalTestRouter(index, *cig.get()); TestRouter(*router, startPos, finalPos, routeFoundByAstarBidirectional); // find route by A* algorithm routing::Route routeFoundByAstar(""); - router = CreatePedestrianAStarTestRouter(index); + router = CreatePedestrianAStarTestRouter(index, *cig.get()); TestRouter(*router, startPos, finalPos, routeFoundByAstar); @@ -132,14 +165,17 @@ void TestTwoPointsOnFeature(m2::PointD const & startPos, m2::PointD const & fina { classificator::Load(); - CountryFile countryFile(MAP_NAME); - LocalCountryFile localFile = LocalCountryFile::MakeForTesting(MAP_NAME); - Index index; - UNUSED_VALUE(index.RegisterMap(localFile)); - TEST(index.IsLoaded(countryFile), ()); - MwmSet::MwmId const id = index.GetMwmIdByCountryFile(countryFile); - TEST(id.IsAlive(), ()); + + for (auto const & mapFile : kMapFiles) + { + CountryFile countryFile(mapFile); + LocalCountryFile localFile = LocalCountryFile::MakeForTesting(mapFile); + UNUSED_VALUE(index.RegisterMap(localFile)); + TEST(index.IsLoaded(countryFile), ()); + MwmSet::MwmId const id = index.GetMwmIdByCountryFile(countryFile); + TEST(id.IsAlive(), ()); + } vector> startEdges; GetNearestPedestrianEdges(index, startPos, startEdges); @@ -161,14 +197,17 @@ void TestTwoPoints(m2::PointD const & startPos, m2::PointD const & finalPos) { classificator::Load(); - CountryFile countryFile(MAP_NAME); - LocalCountryFile localFile = LocalCountryFile::MakeForTesting(MAP_NAME); - Index index; - UNUSED_VALUE(index.RegisterMap(localFile)); - TEST(index.IsLoaded(countryFile), ()); - MwmSet::MwmId const id = index.GetMwmIdByCountryFile(countryFile); - TEST(id.IsAlive(), ()); + + for (auto const & mapFile : kMapFiles) + { + CountryFile countryFile(mapFile); + LocalCountryFile localFile = LocalCountryFile::MakeForTesting(mapFile); + UNUSED_VALUE(index.RegisterMap(localFile)); + TEST(index.IsLoaded(countryFile), ()); + MwmSet::MwmId const id = index.GetMwmIdByCountryFile(countryFile); + TEST(id.IsAlive(), ()); + } TestRouters(index, startPos, finalPos); }