From 181eff29c7290a0da0391bffce021c6ea7c06028 Mon Sep 17 00:00:00 2001 From: karenzshea Date: Mon, 15 Jan 2018 18:38:14 +0100 Subject: [PATCH] add unit test for split submatch waypoints indices --- include/engine/api/match_api.hpp | 1 + unit_tests/library/coordinates.hpp | 8 +++++ unit_tests/library/match.cpp | 49 ++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/include/engine/api/match_api.hpp b/include/engine/api/match_api.hpp index 7329ab42a..fab73ad27 100644 --- a/include/engine/api/match_api.hpp +++ b/include/engine/api/match_api.hpp @@ -120,6 +120,7 @@ class MatchAPI final : public RouteAPI sub_matchings[matching_index.sub_matching_index] .alternatives_count[matching_index.point_index]; // waypoint indices need to be adjusted if route legs were collapsed + // waypoint parameter assumes there is only one match object if (!parameters.waypoints.empty()) { if (tidy_result.was_waypoint[trace_index]) diff --git a/unit_tests/library/coordinates.hpp b/unit_tests/library/coordinates.hpp index e2cb7e8db..50f6ec4ff 100644 --- a/unit_tests/library/coordinates.hpp +++ b/unit_tests/library/coordinates.hpp @@ -13,6 +13,14 @@ using Latitude = osrm::util::FloatLatitude; using Location = osrm::util::Coordinate; using Locations = std::vector; +inline Locations get_split_trace_locations() +{ + return {{Longitude{7.420202}, Latitude{43.732274}}, + {Longitude{7.422369}, Latitude{43.732282}}, + {Longitude{7.421511}, Latitude{43.734181}}, + {Longitude{7.421489}, Latitude{43.736553}}}; +} + inline Location get_dummy_location() { return {osrm::util::FloatLongitude{7.437069}, osrm::util::FloatLatitude{43.749249}}; diff --git a/unit_tests/library/match.cpp b/unit_tests/library/match.cpp index b7ab027bc..9ac0073b6 100644 --- a/unit_tests/library/match.cpp +++ b/unit_tests/library/match.cpp @@ -64,4 +64,53 @@ BOOST_AUTO_TEST_CASE(test_match) } } +BOOST_AUTO_TEST_CASE(test_match_split) +{ + using namespace osrm; + + auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); + + MatchParameters params; + params.coordinates = get_split_trace_locations(); + params.timestamps = {1,2,1700,1800}; + + json::Object result; + + const auto rc = osrm.Match(params, result); + + BOOST_CHECK(rc == Status::Ok || rc == Status::Error); + const auto code = result.values.at("code").get().value; + BOOST_CHECK_EQUAL(code, "Ok"); + + const auto &tracepoints = result.values.at("tracepoints").get().values; + BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size()); + + const auto &matchings = result.values.at("matchings").get().values; + const auto &number_of_matchings = matchings.size(); + BOOST_CHECK_EQUAL(number_of_matchings, 2); + for (const auto &waypoint : tracepoints) + { + if (waypoint.is>()) + { + BOOST_CHECK(waypoint_check(waypoint)); + const auto &waypoint_object = waypoint.get(); + const auto matchings_index = + waypoint_object.values.at("matchings_index").get().value; + const auto waypoint_index = + waypoint_object.values.at("waypoint_index").get().value; + const auto &route_legs = matchings[matchings_index] + .get() + .values.at("legs") + .get() + .values; + BOOST_CHECK_LT(waypoint_index, route_legs.size() + 1); + BOOST_CHECK_LT(matchings_index, number_of_matchings); + } + else + { + BOOST_CHECK(waypoint.is()); + } + } +} + BOOST_AUTO_TEST_SUITE_END()