diff --git a/routing/routing_tests/index_graph_test.cpp b/routing/routing_tests/index_graph_test.cpp index 6121f93936..de43bd8d5a 100644 --- a/routing/routing_tests/index_graph_test.cpp +++ b/routing/routing_tests/index_graph_test.cpp @@ -671,8 +671,7 @@ UNIT_TEST(IndexGraph_OnlyTopology_1) graph.AddDirectedEdge(2, 3, 2.0); double const expectedWeight = 2.0; - // Firs and last edges are projections. - vector const expectedEdges = {{0, 0}, {0, 1}, {1, 3}, {3, 3}}; + vector const expectedEdges = {{0, 1}, {1, 3}}; TestTopologyGraph(graph, 0, 3, true /* pathFound */, expectedWeight, expectedEdges); TestTopologyGraph(graph, 0, 4, false /* pathFound */, 0.0, {}); @@ -698,8 +697,7 @@ UNIT_TEST(IndexGraph_OnlyTopology_3) graph.AddDirectedEdge(0, 1, 1.0); graph.AddDirectedEdge(1, 0, 1.0); double const expectedWeight = 1.0; - // Firs and last edges are projections. - vector const expectedEdges = {{0, 0}, {0, 1}, {1, 1}}; + vector const expectedEdges = {{0, 1}}; TestTopologyGraph(graph, 0, 1, true /* pathFound */, expectedWeight, expectedEdges); } diff --git a/routing/routing_tests/index_graph_tools.cpp b/routing/routing_tests/index_graph_tools.cpp index 8e3fe944a8..bb863869d9 100644 --- a/routing/routing_tests/index_graph_tools.cpp +++ b/routing/routing_tests/index_graph_tools.cpp @@ -151,47 +151,47 @@ bool TestIndexGraphTopology::FindPath(Vertex start, Vertex finish, double & path // for the end of our path and another loop at start for the bidirectional search. auto const startFeatureId = static_cast(edgeRequests.size()); AddDirectedEdge(edgeRequests, start, start, 0.0); + // |startSegment| corresponds to edge from |start| to |start| which has featureId |startFeatureId| + // and the only segment with segmentIdx |0|. It is a loop so direction does not matter. + auto const startSegment = Segment(kTestNumMwmId, startFeatureId, 0 /* segmentIdx */, + true /* forward */); + auto const finishFeatureId = static_cast(edgeRequests.size()); AddDirectedEdge(edgeRequests, finish, finish, 0.0); + // |finishSegment| corresponds to edge from |finish| to |finish| which has featureId |finishFeatureId| + // and the only segment with segmentIdx |0|. It is a loop so direction does not matter. + auto const finishSegment = Segment(kTestNumMwmId, finishFeatureId, 0 /* segmentIdx */, + true /* forward */); Builder builder(m_numVertices); builder.BuildGraphFromRequests(edgeRequests); auto const worldGraph = builder.PrepareIndexGraph(); CHECK(worldGraph != nullptr, ()); - auto const fakeStart = - MakeFakeEnding(startFeatureId, 0 /* segmentIdx */, m2::PointD::Zero(), *worldGraph); - auto const fakeFinish = - MakeFakeEnding(finishFeatureId, 0 /* segmentIdx */, m2::PointD::Zero(), *worldGraph); + AStarAlgorithm algorithm; + RoutingResult routingResult; - auto starter = MakeStarter(fakeStart, fakeFinish, *worldGraph); + auto const resultCode = algorithm.FindPathBidirectional( + *worldGraph, startSegment, finishSegment, routingResult, {} /* cancellable */, + {} /* onVisitedVertexCallback */, {} /* checkLengthCallback */); - vector routeSegs; - double timeSec; - auto const resultCode = CalculateRoute(*starter, routeSegs, timeSec); - - if (resultCode == AStarAlgorithm::Result::NoPath) + if (resultCode == AStarAlgorithm::Result::NoPath) return false; - CHECK_EQUAL(resultCode, AStarAlgorithm::Result::OK, ()); + CHECK_EQUAL(resultCode, AStarAlgorithm::Result::OK, ()); - CHECK_GREATER_OR_EQUAL(routeSegs.size(), 2, ()); - CHECK_EQUAL(routeSegs.front(), starter->GetStartSegment(), ()); - CHECK_EQUAL(routeSegs.back(), starter->GetFinishSegment(), ()); + CHECK_GREATER_OR_EQUAL(routingResult.m_path.size(), 2, ()); + CHECK_EQUAL(routingResult.m_path.front(), startSegment, ()); + CHECK_EQUAL(routingResult.m_path.back(), finishSegment, ()); - // We are not interested in the fake start and finish. - pathEdges.resize(routeSegs.size() - 2); + pathEdges.reserve(routingResult.m_path.size()); pathWeight = 0.0; - for (size_t i = 1; i + 1 < routeSegs.size(); ++i) + for (auto const & s : routingResult.m_path) { - auto seg = routeSegs[i]; - if (!starter->ConvertToReal(seg)) - continue; - - auto const it = builder.m_segmentToEdge.find(seg); + auto const it = builder.m_segmentToEdge.find(s); CHECK(it != builder.m_segmentToEdge.cend(), ()); auto const & edge = it->second; - pathEdges[i - 1] = edge; - pathWeight += builder.m_segmentWeights[seg]; + pathEdges.push_back(edge); + pathWeight += builder.m_segmentWeights[s]; } // The loops from start to start and from finish to finish. diff --git a/routing/routing_tests/road_access_test.cpp b/routing/routing_tests/road_access_test.cpp index 34d9775949..79dfe92845 100644 --- a/routing/routing_tests/road_access_test.cpp +++ b/routing/routing_tests/road_access_test.cpp @@ -108,13 +108,12 @@ UNIT_TEST(RoadAccess_BarrierBypassing) vector expectedEdges; expectedWeight = 3.0; - // First and last edges are projectios - expectedEdges = {{0, 0}, {0, 1}, {1, 2}, {2, 5}, {5, 5}}; + expectedEdges = {{0, 1}, {1, 2}, {2, 5}}; TestTopologyGraph(graph, 0, 5, true /* pathFound */, expectedWeight, expectedEdges); graph.BlockEdge(1, 2); expectedWeight = 4.0; - expectedEdges = {{0, 0}, {0, 3}, {3, 4}, {4, 5}, {5, 5}}; + expectedEdges = {{0, 3}, {3, 4}, {4, 5}}; TestTopologyGraph(graph, 0, 5, true /* pathFound */, expectedWeight, expectedEdges); graph.BlockEdge(3, 4);