From cae333f7880954c0a1cca89d4a67c96c661b0a6c Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Thu, 12 Oct 2023 13:24:05 -0300 Subject: [PATCH] [routing][tests] Updated integration tests. Follow up 6d3e7db0896c3b36265014c9a2bcfc248fbe1f60. Signed-off-by: Viktor Govako --- routing/geometry.cpp | 37 ++++++++++--------- .../bicycle_route_test.cpp | 2 +- .../bicycle_turn_test.cpp | 28 +++++++------- .../pedestrian_route_test.cpp | 2 + .../routing_integration_tests/route_test.cpp | 9 ++++- .../routing_integration_tests/turn_test.cpp | 11 ++++-- 6 files changed, 51 insertions(+), 38 deletions(-) diff --git a/routing/geometry.cpp b/routing/geometry.cpp index 1f294c53da..be662706aa 100644 --- a/routing/geometry.cpp +++ b/routing/geometry.cpp @@ -217,26 +217,27 @@ void RoadGeometry::Load(VehicleModelInterface const & vehicleModel, FeatureType } m_distances.resize(count - 1, -1); - /// @todo Take out this logic into VehicleModel::GetSpeed to include - /// RouteShuttleTrain for bicycle and pedestrian. - if (m_routingOptions.Has(RoutingOptions::Road::Ferry)) + bool const isFerry = m_routingOptions.Has(RoutingOptions::Road::Ferry); + /// @todo Add RouteShuttleTrain into RoutingOptions? + if (isFerry || (m_highwayType && *m_highwayType == HighwayType::RouteShuttleTrain)) { - /// @todo Also process "interval" OSM tag (without additional boarding penalties). - // https://github.com/organicmaps/organicmaps/issues/3695 - - auto const roadLenKm = GetRoadLengthM() / 1000.0; - double const durationH = CalcFerryDurationHours(feature.GetMetadata(feature::Metadata::FMD_DURATION), roadLenKm); - CHECK(!base::AlmostEqualAbs(durationH, 0.0, 1e-5), (durationH)); - - if (roadLenKm != 0.0) + // Skip shuttle train calculation without duration. + auto const durationMeta = feature.GetMetadata(feature::Metadata::FMD_DURATION); + if (isFerry || !durationMeta.empty()) { - double const speed = roadLenKm / durationH; - /// @todo Can fire now if you transit through some fast ferry. Can do one of the following: - /// - Remove assert, but update A* algo heuristic somehow; - /// - Reconsider ferry defaults; - /// - Make _very big_ bicycle/pedestrian maxspeed; - ASSERT_LESS_OR_EQUAL(speed, vehicleModel.GetMaxWeightSpeed(), (roadLenKm, durationH, fID)); - m_forwardSpeed = m_backwardSpeed = SpeedKMpH(speed); + /// @todo Also process "interval" OSM tag (without additional boarding penalties). + // https://github.com/organicmaps/organicmaps/issues/3695 + + auto const roadLenKm = GetRoadLengthM() / 1000.0; + double const durationH = CalcFerryDurationHours(durationMeta, roadLenKm); + CHECK(!base::AlmostEqualAbs(durationH, 0.0, 1e-5), (durationH)); + + if (roadLenKm != 0.0) + { + double const speed = roadLenKm / durationH; + ASSERT_LESS_OR_EQUAL(speed, vehicleModel.GetMaxWeightSpeed(), (roadLenKm, durationH, fID)); + m_forwardSpeed = m_backwardSpeed = SpeedKMpH(speed); + } } } diff --git a/routing/routing_integration_tests/bicycle_route_test.cpp b/routing/routing_integration_tests/bicycle_route_test.cpp index 0709b55cfc..fff25ece1f 100644 --- a/routing/routing_integration_tests/bicycle_route_test.cpp +++ b/routing/routing_integration_tests/bicycle_route_test.cpp @@ -194,7 +194,7 @@ UNIT_TEST(London_GreenwichTunnel) // Has bicycle=yes, because it belongs to https://www.openstreetmap.org/relation/9063263 CalculateRouteAndTestRouteLength(GetVehicleComponents(VehicleType::Bicycle), mercator::FromLatLon(51.4817397, -0.0100070258), {0.0, 0.0}, - mercator::FromLatLon(51.4883739, -0.00809729298), 1010.14 /* expectedRouteMeters */); + mercator::FromLatLon(51.4883739, -0.00809729298), 1305.81 /* expectedRouteMeters */); } UNIT_TEST(Batumi_AvoidServiceDetour) diff --git a/routing/routing_integration_tests/bicycle_turn_test.cpp b/routing/routing_integration_tests/bicycle_turn_test.cpp index 0571026512..e5427e5f2f 100644 --- a/routing/routing_integration_tests/bicycle_turn_test.cpp +++ b/routing/routing_integration_tests/bicycle_turn_test.cpp @@ -214,10 +214,11 @@ UNIT_TEST(TurnsNearMoscowRiverShortFakeSegmentTest) TEST_EQUAL(result, RouterResultCode::NoError, ()); // Closest snapping road is a footway on East, and there are 2 turns, obviously. - integration::TestTurnCount(route, 2 /* expectedTurnCount */); + integration::TestTurnCount(route, 3 /* expectedTurnCount */); integration::GetNthTurn(route, 0).TestValid().TestDirection(CarDirection::TurnRight); integration::GetNthTurn(route, 1).TestValid().TestDirection(CarDirection::TurnRight); + integration::GetNthTurn(route, 2).TestValid().TestDirection(CarDirection::TurnRight); integration::TestRouteLength(route, 401.2); } @@ -234,23 +235,24 @@ UNIT_TEST(TurnsNearMKAD85kmShortFakeSegmentTest) RouterResultCode const result = routeResult.second; TEST_EQUAL(result, RouterResultCode::NoError, ()); - TestRouteLength(route, 1700); + TestRouteLength(route, 1685.31); - TestTurnCount(route, 9); + TestTurnCount(route, 10); GetNthTurn(route, 0).TestValid().TestDirection(CarDirection::TurnRight); - GetNthTurn(route, 1).TestValid().TestDirection(CarDirection::GoStraight); // Fix after "small segment" below. - GetNthTurn(route, 2).TestValid().TestDirection(CarDirection::TurnRight); - GetNthTurn(route, 3).TestValid().TestDirection(CarDirection::EnterRoundAbout); - GetNthTurn(route, 4).TestValid().TestDirection(CarDirection::LeaveRoundAbout); - GetNthTurn(route, 5).TestValid().TestDirection(CarDirection::EnterRoundAbout); - GetNthTurn(route, 6).TestValid().TestDirection(CarDirection::LeaveRoundAbout); - GetNthTurn(route, 7).TestValid().TestDirection(CarDirection::TurnRight); - GetNthTurn(route, 8).TestValid().TestDirection(CarDirection::TurnLeft); + GetNthTurn(route, 1).TestValid().TestDirection(CarDirection::TurnSlightLeft); + GetNthTurn(route, 2).TestValid().TestDirection(CarDirection::TurnSlightLeft); + GetNthTurn(route, 3).TestValid().TestDirection(CarDirection::TurnRight); + GetNthTurn(route, 4).TestValid().TestDirection(CarDirection::EnterRoundAbout); + GetNthTurn(route, 5).TestValid().TestDirection(CarDirection::LeaveRoundAbout); + GetNthTurn(route, 6).TestValid().TestDirection(CarDirection::EnterRoundAbout); + GetNthTurn(route, 7).TestValid().TestDirection(CarDirection::LeaveRoundAbout); + GetNthTurn(route, 8).TestValid().TestDirection(CarDirection::TurnRight); + GetNthTurn(route, 9).TestValid().TestDirection(CarDirection::TurnLeft); /// @todo Should fix this small segment. CalculateRouteAndTestRouteLength(GetVehicleComponents(VehicleType::Bicycle), - mercator::FromLatLon(55.9164647, 37.5862981), {0.0, 0.0}, - mercator::FromLatLon(55.9147746, 37.5852526), 200, 0.005); + mercator::FromLatLon(55.9164523, 37.5867809), {0.0, 0.0}, + mercator::FromLatLon(55.914489, 37.5850912), 260.482, 0.005); } UNIT_TEST(TurnsNearKhladkombinatTest) diff --git a/routing/routing_integration_tests/pedestrian_route_test.cpp b/routing/routing_integration_tests/pedestrian_route_test.cpp index d66f178930..548813c9f2 100644 --- a/routing/routing_integration_tests/pedestrian_route_test.cpp +++ b/routing/routing_integration_tests/pedestrian_route_test.cpp @@ -503,6 +503,8 @@ UNIT_TEST(SwitzerlandSaintBlaisePedestrianPastFerry) { // New value has bigger ditance (+100 meters), but better ETA (-1 minute). // Check with intermediate point {47.0098, 6.9770} + + /// @todo After reducing GetFerryLandingPenalty, the app takes ferry here (1184 meters, 708 seconds). integration::CalculateRouteAndTestRouteLength( integration::GetVehicleComponents(VehicleType::Pedestrian), mercator::FromLatLon(47.010336, 6.982954), {0.0, 0.0}, diff --git a/routing/routing_integration_tests/route_test.cpp b/routing/routing_integration_tests/route_test.cpp index 7e7728a5f8..6925c8cec7 100644 --- a/routing/routing_integration_tests/route_test.cpp +++ b/routing/routing_integration_tests/route_test.cpp @@ -174,8 +174,13 @@ UNIT_TEST(RussiaMoscowFranceParisCenterRouteTest) UNIT_TEST(EnglandToFranceRouteLeMansTest) { - CalculateRouteAndTestRouteLength(GetVehicleComponents(VehicleType::Car), - FromLatLon(51.09276, 1.11369), {0., 0.}, FromLatLon(50.93227, 1.82725), 64755.6); + TRouteResult const res = CalculateRoute(GetVehicleComponents(VehicleType::Car), + FromLatLon(51.09276, 1.11369), {0., 0.}, + FromLatLon(50.93227, 1.82725)); + + TestRouteLength(*res.first, 64089.4); + // LeMans shuttle duration is 35 min. + TEST_LESS(res.first->GetTotalTimeSec(), 3200, ()); } UNIT_TEST(RussiaMoscowStartAtTwowayFeatureTest) diff --git a/routing/routing_integration_tests/turn_test.cpp b/routing/routing_integration_tests/turn_test.cpp index c65d8922e4..9ea3b24872 100644 --- a/routing/routing_integration_tests/turn_test.cpp +++ b/routing/routing_integration_tests/turn_test.cpp @@ -177,14 +177,17 @@ UNIT_TEST(Russia_Moscow_NoTurnsOnMKAD_TurnTest) RouterResultCode const result = routeResult.second; TEST_EQUAL(result, RouterResultCode::NoError, ()); - integration::TestTurnCount(route, 2 /* expectedTurnCount */); + integration::TestTurnCount(route, 3 /* expectedTurnCount */); + /// @todo 0-turn is dummy, https://www.openstreetmap.org/note/3937098 integration::GetNthTurn(route, 1) .TestValid() - /// @todo Update with actual point later. Looks like there is a construction on that junction now. - //.TestPoint({37.68276, 67.14062}) + .TestPoint(mercator::FromLatLon(55.5730008, 37.6792393)) .TestDirection(CarDirection::ExitHighwayToRight); + integration::GetNthTurn(route, 2) + .TestValid() + .TestDirection(CarDirection::TurnSlightRight); - integration::TestRouteLength(route, 43233.7); + integration::TestRouteLength(route, 43228); } UNIT_TEST(Russia_Moscow_TTKVarshavskoeShosseOut_TurnTest)