diff --git a/routing/routing_tests/astar_algorithm_test.cpp b/routing/routing_tests/astar_algorithm_test.cpp index f609a1142f7..cb0d368b373 100644 --- a/routing/routing_tests/astar_algorithm_test.cpp +++ b/routing/routing_tests/astar_algorithm_test.cpp @@ -18,6 +18,14 @@ using namespace std; using Algorithm = AStarAlgorithm; +void TestOnRouteGeomAndDistance( + RoutingResult const & actualRoute, + vector const & expectedRoute, double const & expectedDistance) +{ + TEST_EQUAL(expectedRoute, actualRoute.m_path, ()); + TEST_ALMOST_EQUAL_ULPS(expectedDistance, actualRoute.m_distance, ()); +} + void TestAStar(UndirectedGraph & graph, vector const & expectedRoute, double const & expectedDistance) { Algorithm algo; @@ -25,16 +33,23 @@ void TestAStar(UndirectedGraph & graph, vector const & expectedRoute, Algorithm::ParamsForTests<> params(graph, 0u /* startVertex */, 4u /* finishVertex */, nullptr /* prevRoute */); + // Algorithm::FindPath() testing. RoutingResult actualRoute; TEST_EQUAL(Algorithm::Result::OK, algo.FindPath(params, actualRoute), ()); - TEST_EQUAL(expectedRoute, actualRoute.m_path, ()); - TEST_ALMOST_EQUAL_ULPS(expectedDistance, actualRoute.m_distance, ()); + TestOnRouteGeomAndDistance(actualRoute, expectedRoute, expectedDistance); + // Algorithm::FindPathBidirectional() in one thread testing. actualRoute.m_path.clear(); TEST_EQUAL(Algorithm::Result::OK, algo.FindPathBidirectional(params, actualRoute), ()); - TEST_EQUAL(expectedRoute, actualRoute.m_path, ()); - TEST_ALMOST_EQUAL_ULPS(expectedDistance, actualRoute.m_distance, ()); + TestOnRouteGeomAndDistance(actualRoute, expectedRoute, expectedDistance); + + // Algorithm::FindPathBidirectional() in two thread testing. + actualRoute.m_path.clear(); + graph.SetTwoThreadsReady(true); + TEST_EQUAL(Algorithm::Result::OK, + algo.FindPathBidirectional(params, actualRoute), ()); + TestOnRouteGeomAndDistance(actualRoute, expectedRoute, expectedDistance); } UNIT_TEST(AStarAlgorithm_Sample) diff --git a/routing/routing_tests/routing_algorithm.cpp b/routing/routing_tests/routing_algorithm.cpp index b0759083970..283d6bddbb6 100644 --- a/routing/routing_tests/routing_algorithm.cpp +++ b/routing/routing_tests/routing_algorithm.cpp @@ -18,7 +18,6 @@ namespace routing_test { UndirectedGraph::UndirectedGraph() { - CHECK(!IsTwoThreadsReady(), ()); } void UndirectedGraph::AddEdge(Vertex u, Vertex v, Weight w) diff --git a/routing/routing_tests/routing_algorithm.hpp b/routing/routing_tests/routing_algorithm.hpp index 1cb53a89a13..aa02e027401 100644 --- a/routing/routing_tests/routing_algorithm.hpp +++ b/routing/routing_tests/routing_algorithm.hpp @@ -42,14 +42,20 @@ class UndirectedGraph : public AStarGraph void GetOutgoingEdgesList(astar::VertexData const & vertexData, std::vector & adj) override; double HeuristicCostEstimate(Vertex const & v, Vertex const & w, bool isOutgoing) override; + virtual bool IsTwoThreadsReady() const override { return m_twoThreadsReady; } // @} void GetEdgesList(Vertex const & vertex, bool /* isOutgoing */, std::vector & adj); + /// \note If |twoThreadsRead| is equal to true it means class should be ready that methods + /// GetIngoingEdgesList(), GetOutgoingEdgesList() and HeuristicCostEstimate() are called + /// from two threads depending on |isOutgoing| parameter. + void SetTwoThreadsReady(bool twoThreadsRead) { m_twoThreadsReady = twoThreadsRead; } private: void GetAdjacencyList(Vertex v, std::vector & adj) const; std::map> m_adjs; + bool m_twoThreadsReady = false; }; class DirectedGraph