diff --git a/unit_tests/library/coordinates.hpp b/unit_tests/library/coordinates.hpp index 1c622b59f..2ccc689a8 100644 --- a/unit_tests/library/coordinates.hpp +++ b/unit_tests/library/coordinates.hpp @@ -20,8 +20,7 @@ inline Location get_dummy_location() inline Locations get_locations_in_small_component() { - return {{Longitude{7.437246}, Latitude{43.747225}}, - {Longitude{7.438023}, Latitude{43.746465}}, + return {{Longitude{7.438023}, Latitude{43.746465}}, {Longitude{7.439263}, Latitude{43.746543}}, {Longitude{7.438190}, Latitude{43.747560}}}; } diff --git a/unit_tests/library/nearest.cpp b/unit_tests/library/nearest.cpp index c4c1b9b07..3b631ccd1 100644 --- a/unit_tests/library/nearest.cpp +++ b/unit_tests/library/nearest.cpp @@ -79,4 +79,38 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_multiple_coordinates) BOOST_CHECK_EQUAL(code, "InvalidOptions"); } +BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component) +{ + const auto args = get_args(); + auto osrm = get_osrm(args.at(0)); + + using namespace osrm; + + const auto locations = get_locations_in_small_component(); + + NearestParameters params; + params.coordinates.push_back(locations.at(0)); + params.number_of_results = 3; + + json::Object result; + const auto rc = osrm.Nearest(params, result); + BOOST_REQUIRE(rc == Status::Ok); + + const auto code = result.values.at("code").get().value; + BOOST_CHECK_EQUAL(code, "ok"); + + const auto &waypoints = result.values.at("waypoints").get().values; + BOOST_CHECK(!waypoints.empty()); + + for (const auto &waypoint : waypoints) + { + const auto &waypoint_object = waypoint.get(); + + // Everything within ~20m (actually more) is still in small component. + // Nearest service should snap to road network without considering components. + const auto distance = waypoint_object.values.at("distance").get().value; + BOOST_CHECK_LT(distance, 20); + } +} + BOOST_AUTO_TEST_SUITE_END()