more table tests, break waypoint obj check into header file
This commit is contained in:
parent
1489662f57
commit
324f1739e4
@ -4,6 +4,7 @@
|
|||||||
#include "args.hpp"
|
#include "args.hpp"
|
||||||
#include "fixture.hpp"
|
#include "fixture.hpp"
|
||||||
#include "coordinates.hpp"
|
#include "coordinates.hpp"
|
||||||
|
#include "waypoint_check.hpp"
|
||||||
|
|
||||||
#include "osrm/match_parameters.hpp"
|
#include "osrm/match_parameters.hpp"
|
||||||
|
|
||||||
@ -46,12 +47,8 @@ BOOST_AUTO_TEST_CASE(test_match)
|
|||||||
{
|
{
|
||||||
if (waypoint.is<mapbox::util::recursive_wrapper<util::json::Object>>())
|
if (waypoint.is<mapbox::util::recursive_wrapper<util::json::Object>>())
|
||||||
{
|
{
|
||||||
|
BOOST_CHECK(waypoint_check(waypoint));
|
||||||
const auto &waypoint_object = waypoint.get<json::Object>();
|
const auto &waypoint_object = waypoint.get<json::Object>();
|
||||||
const auto &waypoint_object_location = waypoint_object.values.at("location").get<json::Array>().values;
|
|
||||||
util::FloatLongitude lon(waypoint_object_location[0].get<json::Number>().value);
|
|
||||||
util::FloatLatitude lat(waypoint_object_location[1].get<json::Number>().value);
|
|
||||||
util::Coordinate location_coordinate(lon, lat);
|
|
||||||
BOOST_CHECK(location_coordinate.IsValid());
|
|
||||||
const auto matchings_index = waypoint_object.values.at("matchings_index").get<json::Number>().value;
|
const auto matchings_index = waypoint_object.values.at("matchings_index").get<json::Number>().value;
|
||||||
const auto waypoint_index = waypoint_object.values.at("waypoint_index").get<json::Number>().value;
|
const auto waypoint_index = waypoint_object.values.at("waypoint_index").get<json::Number>().value;
|
||||||
const auto &route_legs = matchings[matchings_index].get<json::Object>().values.at("legs").get<json::Array>().values;
|
const auto &route_legs = matchings[matchings_index].get<json::Object>().values.at("legs").get<json::Array>().values;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "args.hpp"
|
#include "args.hpp"
|
||||||
#include "coordinates.hpp"
|
#include "coordinates.hpp"
|
||||||
#include "fixture.hpp"
|
#include "fixture.hpp"
|
||||||
|
#include "waypoint_check.hpp"
|
||||||
|
|
||||||
#include "osrm/table_parameters.hpp"
|
#include "osrm/table_parameters.hpp"
|
||||||
|
|
||||||
@ -15,17 +16,106 @@
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(table)
|
BOOST_AUTO_TEST_SUITE(table)
|
||||||
|
|
||||||
// TODO
|
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix)
|
||||||
//
|
{
|
||||||
// three coordinates input, no options returns 3x3 matrix
|
const auto args = get_args();
|
||||||
// three coordinates input, one source returns 1x3 matrix
|
BOOST_REQUIRE_EQUAL(args.size(), 1);
|
||||||
// three coordinate input, one source, one destination returns 1x1 matrix
|
|
||||||
// break out waypoint object array checker into header file
|
using namespace osrm;
|
||||||
//
|
|
||||||
|
auto osrm = getOSRM(args[0]);
|
||||||
|
|
||||||
|
TableParameters params;
|
||||||
|
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);
|
||||||
|
|
||||||
|
json::Object result;
|
||||||
|
|
||||||
|
const auto rc = osrm.Table(params, result);
|
||||||
|
|
||||||
|
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
|
||||||
|
const auto code = 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 = 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 destinations array of waypoint objects
|
||||||
|
const auto &destinations_array = result.values.at("destinations").get<json::Array>().values;
|
||||||
|
BOOST_CHECK_EQUAL(destinations_array.size(), params.destinations.size());
|
||||||
|
for (const auto &destination : destinations_array)
|
||||||
|
{
|
||||||
|
BOOST_CHECK(waypoint_check(destination));
|
||||||
|
}
|
||||||
|
// check sources array of waypoint objects
|
||||||
|
const auto &sources_array = result.values.at("sources").get<json::Array>().values;
|
||||||
|
BOOST_CHECK_EQUAL(sources_array.size(), params.sources.size());
|
||||||
|
for (const auto &source : sources_array)
|
||||||
|
{
|
||||||
|
BOOST_CHECK(waypoint_check(source));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix)
|
||||||
|
{
|
||||||
|
const auto args = get_args();
|
||||||
|
BOOST_REQUIRE_EQUAL(args.size(), 1);
|
||||||
|
|
||||||
|
using namespace osrm;
|
||||||
|
|
||||||
|
auto osrm = getOSRM(args[0]);
|
||||||
|
|
||||||
|
TableParameters params;
|
||||||
|
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);
|
||||||
|
|
||||||
|
json::Object result;
|
||||||
|
|
||||||
|
const auto rc = osrm.Table(params, result);
|
||||||
|
|
||||||
|
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
|
||||||
|
const auto code = 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 1x3 matrix
|
||||||
|
const auto &durations_array = 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[i].get<json::Number>().value, 0);
|
||||||
|
BOOST_CHECK_EQUAL(durations_matrix.size(), params.sources.size()*params.coordinates.size());
|
||||||
|
}
|
||||||
|
// check destinations array of waypoint objects
|
||||||
|
const auto &destinations_array = result.values.at("destinations").get<json::Array>().values;
|
||||||
|
BOOST_CHECK_EQUAL(destinations_array.size(), params.coordinates.size());
|
||||||
|
for (const auto &destination : destinations_array)
|
||||||
|
{
|
||||||
|
BOOST_CHECK(waypoint_check(destination));
|
||||||
|
}
|
||||||
|
// check sources array of waypoint objects
|
||||||
|
const auto &sources_array = result.values.at("sources").get<json::Array>().values;
|
||||||
|
BOOST_CHECK_EQUAL(sources_array.size(), params.sources.size());
|
||||||
|
for (const auto &source : sources_array)
|
||||||
|
{
|
||||||
|
BOOST_CHECK(waypoint_check(source));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix)
|
BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix)
|
||||||
{
|
{
|
||||||
|
|
||||||
const auto args = get_args();
|
const auto args = get_args();
|
||||||
BOOST_REQUIRE_EQUAL(args.size(), 1);
|
BOOST_REQUIRE_EQUAL(args.size(), 1);
|
||||||
|
|
||||||
@ -46,6 +136,8 @@ BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix)
|
|||||||
const auto code = result.values.at("code").get<json::String>().value;
|
const auto code = result.values.at("code").get<json::String>().value;
|
||||||
BOOST_CHECK_EQUAL(code, "Ok");
|
BOOST_CHECK_EQUAL(code, "Ok");
|
||||||
|
|
||||||
|
// check that returned durations error is expected size and proportions
|
||||||
|
// this test expects a 3x3 matrix
|
||||||
const auto &durations_array = result.values.at("durations").get<json::Array>().values;
|
const auto &durations_array = result.values.at("durations").get<json::Array>().values;
|
||||||
BOOST_CHECK_EQUAL(durations_array.size(), params.coordinates.size());
|
BOOST_CHECK_EQUAL(durations_array.size(), params.coordinates.size());
|
||||||
for (unsigned int i = 0; i < durations_array.size(); i++)
|
for (unsigned int i = 0; i < durations_array.size(); i++)
|
||||||
@ -57,23 +149,13 @@ BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix)
|
|||||||
const auto &destinations_array = result.values.at("destinations").get<json::Array>().values;
|
const auto &destinations_array = result.values.at("destinations").get<json::Array>().values;
|
||||||
for (const auto &destination : destinations_array)
|
for (const auto &destination : destinations_array)
|
||||||
{
|
{
|
||||||
const auto &dest_object = destination.get<json::Object>();
|
BOOST_CHECK(waypoint_check(destination));
|
||||||
const auto &dest_location = dest_object.values.at("location").get<json::Array>().values;
|
|
||||||
util::FloatLongitude lon(dest_location[0].get<json::Number>().value);
|
|
||||||
util::FloatLatitude lat(dest_location[1].get<json::Number>().value);
|
|
||||||
util::Coordinate location_coordinate(lon, lat);
|
|
||||||
BOOST_CHECK(location_coordinate.IsValid());
|
|
||||||
}
|
}
|
||||||
const auto &sources_array = result.values.at("sources").get<json::Array>().values;
|
const auto &sources_array = result.values.at("sources").get<json::Array>().values;
|
||||||
BOOST_CHECK_EQUAL(sources_array.size(), params.coordinates.size());
|
BOOST_CHECK_EQUAL(sources_array.size(), params.coordinates.size());
|
||||||
for (const auto &destination : destinations_array)
|
for (const auto &source : sources_array)
|
||||||
{
|
{
|
||||||
const auto &dest_object = destination.get<json::Object>();
|
BOOST_CHECK(waypoint_check(source));
|
||||||
const auto &dest_location = dest_object.values.at("location").get<json::Array>().values;
|
|
||||||
util::FloatLongitude lon(dest_location[0].get<json::Number>().value);
|
|
||||||
util::FloatLatitude lat(dest_location[1].get<json::Number>().value);
|
|
||||||
util::Coordinate location_coordinate(lon, lat);
|
|
||||||
BOOST_CHECK(location_coordinate.IsValid());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
unit_tests/library/waypoint_check.hpp
Normal file
24
unit_tests/library/waypoint_check.hpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef OSRM_UNIT_TEST_WAYPOINT_CHECK
|
||||||
|
#define OSRM_UNIT_TEST_WAYPOINT_CHECK
|
||||||
|
|
||||||
|
#include "osrm/coordinate.hpp"
|
||||||
|
#include "osrm/json_container.hpp"
|
||||||
|
#include "util/exception.hpp"
|
||||||
|
|
||||||
|
using namespace osrm;
|
||||||
|
|
||||||
|
inline bool waypoint_check(json::Value waypoint)
|
||||||
|
{
|
||||||
|
if (!waypoint.is<mapbox::util::recursive_wrapper<util::json::Object>>())
|
||||||
|
{
|
||||||
|
throw util::exception("Must pass in a waypoint object");
|
||||||
|
}
|
||||||
|
const auto waypoint_object = waypoint.get<json::Object>();
|
||||||
|
const auto waypoint_location = waypoint_object.values.at("location").get<json::Array>().values;
|
||||||
|
util::FloatLongitude lon(waypoint_location[0].get<json::Number>().value);
|
||||||
|
util::FloatLatitude lat(waypoint_location[1].get<json::Number>().value);
|
||||||
|
util::Coordinate location_coordinate(lon, lat);
|
||||||
|
return location_coordinate.IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user