diff --git a/routing/cross_mwm_ids.hpp b/routing/cross_mwm_ids.hpp index 853a0b083e..f912760cb8 100644 --- a/routing/cross_mwm_ids.hpp +++ b/routing/cross_mwm_ids.hpp @@ -23,6 +23,12 @@ struct TransitId DECLARE_VISITOR_AND_DEBUG_PRINT(TransitId, visitor(m_stop1Id, "stop1_id"), visitor(m_stop2Id, "stop2_id"), visitor(m_lineId, "line_id")) + TransitId() = default; + TransitId(transit::StopId stop1Id, transit::StopId stop2Id, transit::LineId lineId) + : m_stop1Id(stop1Id), m_stop2Id(stop2Id), m_lineId(lineId) + { + } + bool operator==(TransitId const & rhs) const { return m_stop1Id == rhs.m_stop1Id && m_stop2Id == rhs.m_stop2Id && m_lineId == rhs.m_lineId; diff --git a/routing/routing_tests/cross_mwm_connector_test.cpp b/routing/routing_tests/cross_mwm_connector_test.cpp index 74190aeba1..dc3057ca9a 100644 --- a/routing/routing_tests/cross_mwm_connector_test.cpp +++ b/routing/routing_tests/cross_mwm_connector_test.cpp @@ -37,18 +37,15 @@ void TestEdges(CrossMwmConnector const & connector, Segment const & connector.GetEdgeList(from, isOutgoing, edges); TEST_EQUAL(edges, expectedEdges, ()); } -} -namespace routing_test +template +void TestOneWayEnter(CrossMwmId const & crossMwmId) { -UNIT_TEST(OneWayEnter) -{ - OsmId constexpr osmId(1ULL); uint32_t constexpr featureId = 1; uint32_t constexpr segmentIdx = 1; - CrossMwmConnector connector(mwmId); - connector.AddTransition(osmId, featureId, segmentIdx, true /* oneWay */, true /* forwardIsEnter */, - {} /* backPoint */, {} /* frontPoint */); + CrossMwmConnector connector(mwmId); + connector.AddTransition(crossMwmId, featureId, segmentIdx, true /* oneWay */, + true /* forwardIsEnter */, {} /* backPoint */, {} /* frontPoint */); TestConnectorConsistency(connector); TEST_EQUAL(connector.GetEnters().size(), 1, ()); @@ -67,14 +64,14 @@ UNIT_TEST(OneWayEnter) ()); } -UNIT_TEST(OneWayExit) +template +void TestOneWayExit(CrossMwmId const & crossMwmId) { - OsmId constexpr osmId(1ULL); uint32_t constexpr featureId = 1; uint32_t constexpr segmentIdx = 1; - CrossMwmConnector connector(mwmId); - connector.AddTransition(osmId, featureId, segmentIdx, true /* oneWay */, false /* forwardIsEnter */, - {} /* backPoint */, {} /* frontPoint */); + CrossMwmConnector connector(mwmId); + connector.AddTransition(crossMwmId, featureId, segmentIdx, true /* oneWay */, + false /* forwardIsEnter */, {} /* backPoint */, {} /* frontPoint */); TestConnectorConsistency(connector); TEST_EQUAL(connector.GetEnters().size(), 0, ()); @@ -93,14 +90,14 @@ UNIT_TEST(OneWayExit) ()); } -UNIT_TEST(TwoWayEnter) +template +void TestTwoWayEnter(CrossMwmId const & crossMwmId) { - OsmId constexpr osmId(1ULL); uint32_t constexpr featureId = 1; uint32_t constexpr segmentIdx = 1; - CrossMwmConnector connector(mwmId); - connector.AddTransition(osmId, featureId, segmentIdx, false /* oneWay */, true /* forwardIsEnter */, - {} /* backPoint */, {} /* frontPoint */); + CrossMwmConnector connector(mwmId); + connector.AddTransition(crossMwmId, featureId, segmentIdx, false /* oneWay */, + true /* forwardIsEnter */, {} /* backPoint */, {} /* frontPoint */); TestConnectorConsistency(connector); TEST_EQUAL(connector.GetEnters().size(), 1, ()); @@ -118,15 +115,14 @@ UNIT_TEST(TwoWayEnter) false /* isOutgoing */), ()); } - -UNIT_TEST(TwoWayExit) +template +void TestTwoWayExit(CrossMwmId const & crossMwmId) { - OsmId constexpr osmId(1ULL); uint32_t constexpr featureId = 1; uint32_t constexpr segmentIdx = 1; - CrossMwmConnector connector(mwmId); - connector.AddTransition(osmId, featureId, segmentIdx, false /* oneWay */, false /* forwardIsEnter */, - {} /* backPoint */, {} /* frontPoint */); + CrossMwmConnector connector(mwmId); + connector.AddTransition(crossMwmId, featureId, segmentIdx, false /* oneWay */, + false /* forwardIsEnter */, {} /* backPoint */, {} /* frontPoint */); TestConnectorConsistency(connector); TEST_EQUAL(connector.GetEnters().size(), 1, ()); @@ -145,20 +141,15 @@ UNIT_TEST(TwoWayExit) ()); } -UNIT_TEST(Serialization) +template +void TestSerialization(vector> const & transitions) { double constexpr kEdgesWeight = 4444.0; vector buffer; { - vector> transitions = { - /* osmId featureId, segmentIdx, roadMask, oneWayMask, forwardIsEnter, backPoint, frontPoint */ - {OsmId(100ULL), 10, 1, kCarMask, kCarMask, true, m2::PointD(1.1, 1.2), m2::PointD(1.3, 1.4)}, - {OsmId(200ULL), 20, 2, kCarMask, 0, true, m2::PointD(2.1, 2.2), m2::PointD(2.3, 2.4)}, - {OsmId(300ULL), 30, 3, kPedestrianMask, kCarMask, true, m2::PointD(3.1, 3.2), m2::PointD(3.3, 3.4)}}; - - CrossMwmConnectorPerVehicleType connectors; - CrossMwmConnector & carConnector = connectors[static_cast(VehicleType::Car)]; + CrossMwmConnectorPerVehicleType connectors; + CrossMwmConnector & carConnector = connectors[static_cast(VehicleType::Car)]; for (auto const & transition : transitions) CrossMwmConnectorSerializer::AddTransition(transition, kCarMask, carConnector); @@ -170,7 +161,7 @@ UNIT_TEST(Serialization) CrossMwmConnectorSerializer::Serialize(transitions, connectors, codingParams, writer); } - CrossMwmConnector connector(mwmId); + CrossMwmConnector connector(mwmId); { MemReader reader(buffer.data(), buffer.size()); ReaderSource source(reader); @@ -218,20 +209,20 @@ UNIT_TEST(Serialization) double constexpr eps = 1e-6; TEST(AlmostEqualAbs( - connector.GetPoint(Segment(mwmId, 20, 2, true /* forward */), true /* front */), - m2::PointD(2.3, 2.4), eps), + connector.GetPoint(Segment(mwmId, 20, 2, true /* forward */), true /* front */), + m2::PointD(2.3, 2.4), eps), ()); TEST(AlmostEqualAbs( - connector.GetPoint(Segment(mwmId, 20, 2, true /* forward */), false /* front */), - m2::PointD(2.1, 2.2), eps), + connector.GetPoint(Segment(mwmId, 20, 2, true /* forward */), false /* front */), + m2::PointD(2.1, 2.2), eps), ()); TEST(AlmostEqualAbs( - connector.GetPoint(Segment(mwmId, 20, 2, false /* forward */), true /* front */), - m2::PointD(2.1, 2.2), eps), + connector.GetPoint(Segment(mwmId, 20, 2, false /* forward */), true /* front */), + m2::PointD(2.1, 2.2), eps), ()); TEST(AlmostEqualAbs( - connector.GetPoint(Segment(mwmId, 20, 2, true /* forward */), true /* front */), - m2::PointD(2.3, 2.4), eps), + connector.GetPoint(Segment(mwmId, 20, 2, true /* forward */), true /* front */), + m2::PointD(2.3, 2.4), eps), ()); TestEdges(connector, Segment(mwmId, 10, 1, true /* forward */), true /* isOutgoing */, @@ -248,7 +239,15 @@ UNIT_TEST(Serialization) {Segment(mwmId, 20, 2, true /* forward */), RouteWeight::FromCrossMwmWeight(kEdgesWeight)}}); } -UNIT_TEST(WeightsSerialization) +void GetCrossMwmId(uint32_t i, OsmId & id) { id.Set(10 * i); } + +void GetCrossMwmId(uint32_t i, TransitId & id) +{ + id = TransitId(1 /* stop 1 id */, 10 * i /* stop 1 id */, 1 /* line id */); +} + +template +void TestWeightsSerialization() { size_t constexpr kNumTransitions = 3; vector const weights = { @@ -257,16 +256,17 @@ UNIT_TEST(WeightsSerialization) vector buffer; { - vector> transitions; + vector> transitions; for (uint32_t featureId = 0; featureId < kNumTransitions; ++featureId) { - auto const osmId = static_cast(featureId * 10); - transitions.emplace_back(connector::OsmId(osmId), featureId, 1 /* segmentIdx */, kCarMask, 0 /* oneWayMask */, + CrossMwmId id; + GetCrossMwmId(featureId, id); + transitions.emplace_back(id, featureId, 1 /* segmentIdx */, kCarMask, 0 /* oneWayMask */, true /* forwardIsEnter */, m2::PointD::Zero(), m2::PointD::Zero()); } - CrossMwmConnectorPerVehicleType connectors; - CrossMwmConnector & carConnector = connectors[static_cast(VehicleType::Car)]; + CrossMwmConnectorPerVehicleType connectors; + CrossMwmConnector & carConnector = connectors[static_cast(VehicleType::Car)]; for (auto const & transition : transitions) CrossMwmConnectorSerializer::AddTransition(transition, kCarMask, carConnector); @@ -279,7 +279,7 @@ UNIT_TEST(WeightsSerialization) CrossMwmConnectorSerializer::Serialize(transitions, connectors, codingParams, writer); } - CrossMwmConnector connector(mwmId); + CrossMwmConnector connector(mwmId); { MemReader reader(buffer.data(), buffer.size()); ReaderSource source(reader); @@ -322,4 +322,62 @@ UNIT_TEST(WeightsSerialization) TestEdges(connector, enter, true /* isOutgoing */, expectedEdges); } } +} // namespace + +namespace routing_test +{ +UNIT_TEST(OneWayEnter) +{ + TestOneWayEnter(OsmId(1ULL)); + TestOneWayEnter(TransitId(1 /* stop 1 id */, 2 /* stop 2 id */, 1 /* line id */)); +} + +UNIT_TEST(OneWayExit) +{ + TestOneWayExit(OsmId(1ULL)); + TestOneWayExit(TransitId(1 /* stop 1 id */, 2 /* stop 2 id */, 1 /* line id */)); +} + +UNIT_TEST(TwoWayEnter) +{ + TestTwoWayEnter(OsmId(1ULL)); + TestTwoWayEnter(TransitId(1 /* stop 1 id */, 2 /* stop 2 id */, 1 /* line id */)); +} + +UNIT_TEST(TwoWayExit) +{ + TestTwoWayExit(OsmId(1ULL)); + TestTwoWayExit(TransitId(1 /* stop 1 id */, 2 /* stop 2 id */, 1 /* line id */)); +} + +UNIT_TEST(Serialization) +{ + { + vector> const transitions = { + /* osmId featureId, segmentIdx, roadMask, oneWayMask, forwardIsEnter, backPoint, frontPoint */ + {OsmId(100ULL), 10, 1, kCarMask, kCarMask, true, m2::PointD(1.1, 1.2), + m2::PointD(1.3, 1.4)}, + {OsmId(200ULL), 20, 2, kCarMask, 0, true, m2::PointD(2.1, 2.2), m2::PointD(2.3, 2.4)}, + {OsmId(300ULL), 30, 3, kPedestrianMask, kCarMask, true, m2::PointD(3.1, 3.2), + m2::PointD(3.3, 3.4)}}; + TestSerialization(transitions); + } + { + vector> const transitions = { + /* osmId featureId, segmentIdx, roadMask, oneWayMask, forwardIsEnter, backPoint, frontPoint */ + {TransitId(1ULL /* stop 1 id */, 2ULL /* stop 2 id */, 1ULL /* line id */), 10, 1, kCarMask, + kCarMask, true, m2::PointD(1.1, 1.2), m2::PointD(1.3, 1.4)}, + {TransitId(1ULL, 3ULL, 1ULL), 20, 2, kCarMask, 0, true, m2::PointD(2.1, 2.2), + m2::PointD(2.3, 2.4)}, + {TransitId(1ULL, 3ULL, 2ULL), 30, 3, kPedestrianMask, kCarMask, true, m2::PointD(3.1, 3.2), + m2::PointD(3.3, 3.4)}}; + TestSerialization(transitions); + } +} + +UNIT_TEST(WeightsSerialization) +{ + TestWeightsSerialization(); + TestWeightsSerialization(); +} } // namespace routing_test