MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / test_match_split

Function test_match_split

unit_tests/library/match.cpp:107–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105BOOST_AUTO_TEST_CASE(test_match_skip_waypoints_new_api) { test_match_skip_waypoints(false); }
106
107void test_match_split(bool use_json_only_api)
108{
109 using namespace osrm;
110
111 auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
112
113 MatchParameters params;
114 params.coordinates = get_split_trace_locations();
115 params.timestamps = {1, 2, 1700, 1800};
116
117 json::Object json_result;
118 const auto rc = run_match_json(osrm, params, json_result, use_json_only_api);
119
120 BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
121 const auto code = std::get<json::String>(json_result.values.at("code")).value;
122 BOOST_CHECK_EQUAL(code, "Ok");
123
124 const auto &tracepoints = std::get<json::Array>(json_result.values.at("tracepoints")).values;
125 BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size());
126
127 const auto &matchings = std::get<json::Array>(json_result.values.at("matchings")).values;
128 const auto &number_of_matchings = matchings.size();
129 BOOST_CHECK_EQUAL(number_of_matchings, 2);
130 std::size_t current_matchings_index = 0, expected_waypoint_index = 0;
131 for (const auto &waypoint : tracepoints)
132 {
133 if (std::holds_alternative<util::json::Object>(waypoint))
134 {
135 BOOST_CHECK(waypoint_check(waypoint));
136 const auto &waypoint_object = std::get<json::Object>(waypoint);
137 const auto matchings_index =
138 std::get<json::Number>(waypoint_object.values.at("matchings_index")).value;
139 const auto waypoint_index =
140 std::get<json::Number>(waypoint_object.values.at("waypoint_index")).value;
141
142 BOOST_CHECK_LT(matchings_index, number_of_matchings);
143
144 expected_waypoint_index =
145 (current_matchings_index != matchings_index) ? 0 : expected_waypoint_index;
146 BOOST_CHECK_EQUAL(waypoint_index, expected_waypoint_index);
147
148 current_matchings_index = matchings_index;
149 ++expected_waypoint_index;
150 }
151 else
152 {
153 BOOST_CHECK(std::holds_alternative<json::Null>(waypoint));
154 }
155 }
156}
157BOOST_AUTO_TEST_CASE(test_match_split_old_api) { test_match_split(true); }
158BOOST_AUTO_TEST_CASE(test_match_split_new_api) { test_match_split(false); }
159

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 6

getOSRMFunction · 0.85
run_match_jsonFunction · 0.85
waypoint_checkFunction · 0.85
atMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected