2016-03-16 07:42:26 -04:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include <boost/test/test_case_template.hpp>
|
|
|
|
|
2016-03-16 09:53:14 -04:00
|
|
|
#include "args.hpp"
|
2016-03-17 10:43:31 -04:00
|
|
|
#include "fixture.hpp"
|
2016-03-16 07:42:26 -04:00
|
|
|
|
|
|
|
#include "osrm/nearest_parameters.hpp"
|
|
|
|
|
|
|
|
#include "osrm/coordinate.hpp"
|
|
|
|
#include "osrm/engine_config.hpp"
|
|
|
|
#include "osrm/json_container.hpp"
|
|
|
|
#include "osrm/status.hpp"
|
|
|
|
#include "osrm/osrm.hpp"
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(nearest)
|
|
|
|
|
2016-03-17 10:43:31 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(test_nearest_response)
|
2016-03-16 07:42:26 -04:00
|
|
|
{
|
|
|
|
const auto args = get_args();
|
2016-03-17 10:43:31 -04:00
|
|
|
auto osrm = get_osrm(args.at(0));
|
2016-03-16 07:42:26 -04:00
|
|
|
|
|
|
|
using namespace osrm;
|
|
|
|
|
2016-03-17 10:43:31 -04:00
|
|
|
NearestParameters params;
|
|
|
|
params.coordinates.emplace_back(util::FloatLongitude{}, util::FloatLatitude{});
|
|
|
|
|
|
|
|
json::Object result;
|
|
|
|
const auto rc = osrm.Nearest(params, result);
|
|
|
|
BOOST_REQUIRE(rc == Status::Ok);
|
|
|
|
|
|
|
|
const auto code = result.values.at("code").get<json::String>().value;
|
|
|
|
BOOST_CHECK_EQUAL(code, "ok");
|
|
|
|
|
|
|
|
const auto &waypoints = result.values.at("waypoints").get<json::Array>().values;
|
|
|
|
BOOST_CHECK(!waypoints.empty()); // the dataset has at least one nearest coordinate
|
2016-03-16 07:42:26 -04:00
|
|
|
|
2016-03-17 10:43:31 -04:00
|
|
|
for (const auto &waypoint : waypoints)
|
|
|
|
{
|
|
|
|
const auto &waypoint_object = waypoint.get<json::Object>();
|
|
|
|
const auto distance = waypoint_object.values.at("distance").get<json::Number>().value;
|
|
|
|
BOOST_CHECK(distance >= 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_nearest_response_no_coordinates)
|
|
|
|
{
|
|
|
|
const auto args = get_args();
|
|
|
|
auto osrm = get_osrm(args.at(0));
|
|
|
|
|
|
|
|
using namespace osrm;
|
2016-03-16 07:42:26 -04:00
|
|
|
|
|
|
|
NearestParameters params;
|
|
|
|
|
|
|
|
json::Object result;
|
2016-03-17 10:43:31 -04:00
|
|
|
const auto rc = osrm.Nearest(params, result);
|
|
|
|
BOOST_REQUIRE(rc == Status::Error);
|
|
|
|
|
|
|
|
const auto code = result.values.at("code").get<json::String>().value;
|
|
|
|
BOOST_CHECK_EQUAL(code, "InvalidOptions");
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_nearest_response_multiple_coordinates)
|
|
|
|
{
|
|
|
|
const auto args = get_args();
|
|
|
|
auto osrm = get_osrm(args.at(0));
|
2016-03-16 07:42:26 -04:00
|
|
|
|
2016-03-17 10:43:31 -04:00
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
NearestParameters params;
|
|
|
|
params.coordinates.emplace_back(util::FloatLongitude{}, util::FloatLatitude{});
|
|
|
|
params.coordinates.emplace_back(util::FloatLongitude{}, util::FloatLatitude{});
|
|
|
|
|
|
|
|
json::Object result;
|
2016-03-16 07:42:26 -04:00
|
|
|
const auto rc = osrm.Nearest(params, result);
|
2016-03-17 10:43:31 -04:00
|
|
|
BOOST_REQUIRE(rc == Status::Error);
|
2016-03-16 07:42:26 -04:00
|
|
|
|
2016-03-17 10:43:31 -04:00
|
|
|
const auto code = result.values.at("code").get<json::String>().value;
|
|
|
|
BOOST_CHECK_EQUAL(code, "TooBig");
|
2016-03-16 07:42:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|