From c0dc3fcf7c06cc8899b0bb6aa75165ed13caa5e6 Mon Sep 17 00:00:00 2001 From: tatiana-kondakova Date: Thu, 21 Sep 2017 13:08:22 +0300 Subject: [PATCH] Add IndexGraphStarter tests for onesegment way with start and finish projected to inverse segment and IndexGraphStarter fake segment coordinates test. --- routing/routing_tests/index_graph_test.cpp | 66 +++++++++++++++++++--- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/routing/routing_tests/index_graph_test.cpp b/routing/routing_tests/index_graph_test.cpp index 6a8dab0129..df60951cb2 100644 --- a/routing/routing_tests/index_graph_test.cpp +++ b/routing/routing_tests/index_graph_test.cpp @@ -22,6 +22,7 @@ #include "std/algorithm.hpp" #include "std/cstdint.hpp" +#include "std/shared_ptr.hpp" #include "std/unique_ptr.hpp" #include "std/unordered_map.hpp" #include "std/vector.hpp" @@ -401,15 +402,23 @@ UNIT_TEST(OneSegmentWay) traffic::TrafficCache const trafficCache; shared_ptr estimator = CreateEstimatorForCar(trafficCache); unique_ptr worldGraph = BuildWorldGraph(move(loader), estimator, vector()); - - auto const start = IndexGraphStarter::MakeFakeEnding( - Segment(kTestNumMwmId, 0, 0, true /* forward */), m2::PointD(1, 0), *worldGraph); - auto const finish = IndexGraphStarter::MakeFakeEnding( - Segment(kTestNumMwmId, 0, 0, true /* forward */), m2::PointD(2, 0), *worldGraph); - vector const expectedRoute( {{kTestNumMwmId, 0 /* featureId */, 0 /* seg id */, true /* forward */}}); - TestRoute(start, finish, expectedRoute.size(), &expectedRoute, *worldGraph); + + // Starter must match any combination of start and finish directions. + vector const tf = {{true, false}}; + for (auto const startIsForward : tf) + { + for (auto const finishIsForward : tf) + { + auto const start = IndexGraphStarter::MakeFakeEnding( + Segment(kTestNumMwmId, 0, 0, startIsForward), m2::PointD(1, 0), *worldGraph); + auto const finish = IndexGraphStarter::MakeFakeEnding( + Segment(kTestNumMwmId, 0, 0, finishIsForward), m2::PointD(2, 0), *worldGraph); + + TestRoute(start, finish, expectedRoute.size(), &expectedRoute, *worldGraph); + } + } } // @@ -445,6 +454,49 @@ UNIT_TEST(OneSegmentWayBackward) TEST_EQUAL(resultCode, AStarAlgorithm::Result::NoPath, ()); } +// Roads y: +// +// R0 * - - - - - * - - - - - * R1 0 +// ^ ^ +// start finish +// +// x: 0 1 2 3 4 +// +UNIT_TEST(FakeSegmentCoordinates) +{ + unique_ptr loader = make_unique(); + + loader->AddRoad(0 /* featureId */, false, 1.0 /* speed */, + RoadGeometry::Points({{0.0, 0.0}, {2.0, 0.0}})); + loader->AddRoad(1 /* featureId */, false, 1.0 /* speed */, + RoadGeometry::Points({{2.0, 0.0}, {4.0, 0.0}})); + + vector joints; + joints.emplace_back(MakeJoint({{0 /* featureId */, 1 /* pointId */}, {1, 0}})); + + traffic::TrafficCache const trafficCache; + shared_ptr estimator = CreateEstimatorForCar(trafficCache); + unique_ptr worldGraph = BuildWorldGraph(move(loader), estimator, joints); + vector const expectedGeom = {{1.0 /* x */, 0.0 /* y */}, {2.0, 0.0}, {3.0, 0.0}}; + + // Test fake segments have valid coordinates for any combination of start and finish directions + vector const tf = {{true, false}}; + for (auto const startIsForward : tf) + { + for (auto const finishIsForward : tf) + { + auto const start = IndexGraphStarter::MakeFakeEnding( + Segment(kTestNumMwmId, 0, 0, startIsForward), m2::PointD(1, 0), *worldGraph); + auto const finish = IndexGraphStarter::MakeFakeEnding( + Segment(kTestNumMwmId, 1, 0, finishIsForward), m2::PointD(3, 0), *worldGraph); + + IndexGraphStarter starter(start, finish, 0 /* fakeNumerationStart */, + false /* strictForward */, *worldGraph); + TestRouteGeometry(starter, AStarAlgorithm::Result::OK, expectedGeom); + } + } +} + // // Road R0 (ped) R1 (car) R2 (car) // 0----------1 * 0----------1 * 0----------1