Added unit tests of 'skip_waypoints' option to the Nearest/Route/Table services.
This commit is contained in:
parent
660c0cc602
commit
a5127539eb
@ -43,6 +43,27 @@ BOOST_AUTO_TEST_CASE(test_nearest_response)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_nearest_response_skip_waypoints)
|
||||
{
|
||||
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
||||
|
||||
using namespace osrm;
|
||||
|
||||
NearestParameters params;
|
||||
params.skip_waypoints = true;
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
|
||||
engine::api::ResultT result = json::Object();
|
||||
const auto rc = osrm.Nearest(params, result);
|
||||
BOOST_REQUIRE(rc == Status::Ok);
|
||||
|
||||
auto &json_result = result.get<json::Object>();
|
||||
const auto code = json_result.values.at("code").get<json::String>().value;
|
||||
BOOST_CHECK_EQUAL(code, "Ok");
|
||||
|
||||
BOOST_CHECK(json_result.values.find("waypoints") == json_result.values.end());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_nearest_response_no_coordinates)
|
||||
{
|
||||
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
||||
@ -118,7 +139,7 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_nearest_fb_serilization)
|
||||
BOOST_AUTO_TEST_CASE(test_nearest_fb_serialization)
|
||||
{
|
||||
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
||||
|
||||
@ -147,6 +168,27 @@ BOOST_AUTO_TEST_CASE(test_nearest_fb_serilization)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_nearest_fb_serialization_skip_waypoints)
|
||||
{
|
||||
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
||||
|
||||
using namespace osrm;
|
||||
|
||||
NearestParameters params;
|
||||
params.skip_waypoints=true;
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
|
||||
engine::api::ResultT result = flatbuffers::FlatBufferBuilder();
|
||||
const auto rc = osrm.Nearest(params, result);
|
||||
BOOST_REQUIRE(rc == Status::Ok);
|
||||
|
||||
auto &fb_result = result.get<flatbuffers::FlatBufferBuilder>();
|
||||
auto fb = engine::api::fbresult::GetFBResult(fb_result.GetBufferPointer());
|
||||
BOOST_CHECK(!fb->error());
|
||||
|
||||
BOOST_CHECK(fb->waypoints() == nullptr);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_nearest_fb_error)
|
||||
{
|
||||
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
||||
|
@ -270,6 +270,53 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_route_same_coordinates_no_waypoints)
|
||||
{
|
||||
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
||||
|
||||
using namespace osrm;
|
||||
|
||||
RouteParameters params;
|
||||
params.skip_waypoints = true;
|
||||
params.steps = true;
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
|
||||
engine::api::ResultT result = json::Object();
|
||||
const auto rc = osrm.Route(params, result);
|
||||
BOOST_CHECK(rc == Status::Ok);
|
||||
|
||||
auto &json_result = result.get<json::Object>();
|
||||
const auto code = json_result.values.at("code").get<json::String>().value;
|
||||
BOOST_CHECK_EQUAL(code, "Ok");
|
||||
|
||||
BOOST_CHECK(json_result.values.find("waypoints") == json_result.values.end());
|
||||
|
||||
const auto &routes = json_result.values.at("routes").get<json::Array>().values;
|
||||
BOOST_REQUIRE_GT(routes.size(), 0);
|
||||
|
||||
for (const auto &route : routes)
|
||||
{
|
||||
const auto &route_object = route.get<json::Object>();
|
||||
|
||||
const auto distance = route_object.values.at("distance").get<json::Number>().value;
|
||||
BOOST_CHECK_EQUAL(distance, 0);
|
||||
|
||||
const auto duration = route_object.values.at("duration").get<json::Number>().value;
|
||||
BOOST_CHECK_EQUAL(duration, 0);
|
||||
|
||||
// geometries=polyline by default
|
||||
const auto geometry = route_object.values.at("geometry").get<json::String>().value;
|
||||
BOOST_CHECK(!geometry.empty());
|
||||
|
||||
const auto &legs = route_object.values.at("legs").get<json::Array>().values;
|
||||
BOOST_CHECK(!legs.empty());
|
||||
|
||||
//The rest of legs contents is verified by test_route_same_coordinates
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_small_component)
|
||||
{
|
||||
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
||||
@ -575,4 +622,43 @@ BOOST_AUTO_TEST_CASE(test_route_serialize_fb)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_route_serialize_fb_skip_waypoints)
|
||||
{
|
||||
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
||||
|
||||
using namespace osrm;
|
||||
|
||||
RouteParameters params;
|
||||
params.skip_waypoints = true;
|
||||
params.steps = true;
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
|
||||
engine::api::ResultT result = flatbuffers::FlatBufferBuilder();
|
||||
const auto rc = osrm.Route(params, result);
|
||||
BOOST_CHECK(rc == Status::Ok);
|
||||
|
||||
auto &fb_result = result.get<flatbuffers::FlatBufferBuilder>();
|
||||
auto fb = engine::api::fbresult::GetFBResult(fb_result.GetBufferPointer());
|
||||
BOOST_CHECK(!fb->error());
|
||||
|
||||
BOOST_CHECK(fb->waypoints() == nullptr);
|
||||
|
||||
BOOST_CHECK(fb->routes() != nullptr);
|
||||
const auto routes = fb->routes();
|
||||
BOOST_REQUIRE_GT(routes->size(), 0);
|
||||
|
||||
for (const auto &route : *routes)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(route->distance(), 0);
|
||||
BOOST_CHECK_EQUAL(route->duration(), 0);
|
||||
|
||||
const auto &legs = route->legs();
|
||||
BOOST_CHECK(legs->size() > 0);
|
||||
|
||||
// Rest of the content is verified by test_route_serialize_fb
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -77,6 +77,57 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix_no_waypoints)
|
||||
{
|
||||
using namespace osrm;
|
||||
|
||||
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
||||
|
||||
TableParameters params;
|
||||
params.skip_waypoints = true;
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
params.sources.push_back(0);
|
||||
params.destinations.push_back(2);
|
||||
params.annotations = TableParameters::AnnotationsType::All;
|
||||
|
||||
engine::api::ResultT result = json::Object();
|
||||
|
||||
const auto rc = osrm.Table(params, result);
|
||||
|
||||
auto &json_result = result.get<json::Object>();
|
||||
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
|
||||
const auto code = json_result.values.at("code").get<json::String>().value;
|
||||
BOOST_CHECK_EQUAL(code, "Ok");
|
||||
|
||||
// check that returned durations error is expected size and proportions
|
||||
// this test expects a 1x1 matrix
|
||||
const auto &durations_array = json_result.values.at("durations").get<json::Array>().values;
|
||||
BOOST_CHECK_EQUAL(durations_array.size(), params.sources.size());
|
||||
for (unsigned int i = 0; i < durations_array.size(); i++)
|
||||
{
|
||||
const auto durations_matrix = durations_array[i].get<json::Array>().values;
|
||||
BOOST_CHECK_EQUAL(durations_matrix.size(),
|
||||
params.sources.size() * params.destinations.size());
|
||||
}
|
||||
|
||||
// check that returned distances error is expected size and proportions
|
||||
// this test expects a 1x1 matrix
|
||||
const auto &distances_array = json_result.values.at("distances").get<json::Array>().values;
|
||||
BOOST_CHECK_EQUAL(distances_array.size(), params.sources.size());
|
||||
for (unsigned int i = 0; i < distances_array.size(); i++)
|
||||
{
|
||||
const auto distances_matrix = distances_array[i].get<json::Array>().values;
|
||||
BOOST_CHECK_EQUAL(distances_matrix.size(),
|
||||
params.sources.size() * params.destinations.size());
|
||||
}
|
||||
|
||||
// waypoint arrays should be missing
|
||||
BOOST_CHECK(json_result.values.find("destinations") == json_result.values.end());
|
||||
BOOST_CHECK(json_result.values.find("sources") == json_result.values.end());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix)
|
||||
{
|
||||
using namespace osrm;
|
||||
@ -247,4 +298,46 @@ BOOST_AUTO_TEST_CASE(test_table_serialiaze_fb)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_table_serialiaze_fb_no_waypoints)
|
||||
{
|
||||
using namespace osrm;
|
||||
|
||||
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
||||
|
||||
TableParameters params;
|
||||
params.skip_waypoints = true;
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
params.coordinates.push_back(get_dummy_location());
|
||||
params.sources.push_back(0);
|
||||
params.destinations.push_back(2);
|
||||
params.annotations = TableParameters::AnnotationsType::All;
|
||||
|
||||
engine::api::ResultT result = flatbuffers::FlatBufferBuilder();
|
||||
|
||||
const auto rc = osrm.Table(params, result);
|
||||
|
||||
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
|
||||
|
||||
auto &fb_result = result.get<flatbuffers::FlatBufferBuilder>();
|
||||
auto fb = engine::api::fbresult::GetFBResult(fb_result.GetBufferPointer());
|
||||
BOOST_CHECK(!fb->error());
|
||||
BOOST_CHECK(fb->table() != nullptr);
|
||||
|
||||
// check that returned durations error is expected size and proportions
|
||||
// this test expects a 1x1 matrix
|
||||
BOOST_CHECK(fb->table()->durations() != nullptr);
|
||||
auto durations_array = fb->table()->durations();
|
||||
BOOST_CHECK_EQUAL(durations_array->size(), params.sources.size() * params.destinations.size());
|
||||
|
||||
// check that returned distances error is expected size and proportions
|
||||
// this test expects a 1x1 matrix
|
||||
BOOST_CHECK(fb->table()->distances() != nullptr);
|
||||
auto distances_array = fb->table()->distances();
|
||||
BOOST_CHECK_EQUAL(distances_array->size(), params.sources.size() * params.destinations.size());
|
||||
|
||||
BOOST_CHECK(fb->table()->destinations() == nullptr);
|
||||
BOOST_CHECK(fb->waypoints() == nullptr);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
Reference in New Issue
Block a user