From 09c40db4ad86daa45b3748ca5f993cf2ab66c775 Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Thu, 17 Mar 2016 15:43:31 +0100 Subject: [PATCH] Unit tests for Nearest service; one test failing: see #2108 --- unit_tests/library/nearest.cpp | 60 +++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/unit_tests/library/nearest.cpp b/unit_tests/library/nearest.cpp index d40863380..b1155dc16 100644 --- a/unit_tests/library/nearest.cpp +++ b/unit_tests/library/nearest.cpp @@ -2,6 +2,7 @@ #include #include "args.hpp" +#include "fixture.hpp" #include "osrm/nearest_parameters.hpp" @@ -13,27 +14,68 @@ BOOST_AUTO_TEST_SUITE(nearest) -BOOST_AUTO_TEST_CASE(test_nearest) +BOOST_AUTO_TEST_CASE(test_nearest_response) { const auto args = get_args(); - BOOST_REQUIRE_EQUAL(args.size(), 1); + auto osrm = get_osrm(args.at(0)); using namespace osrm; - EngineConfig config{args[0]}; - config.use_shared_memory = false; + NearestParameters params; + params.coordinates.emplace_back(util::FloatLongitude{}, util::FloatLatitude{}); - OSRM osrm{config}; + json::Object result; + const auto rc = osrm.Nearest(params, result); + BOOST_REQUIRE(rc == Status::Ok); + + const auto code = result.values.at("code").get().value; + BOOST_CHECK_EQUAL(code, "ok"); + + const auto &waypoints = result.values.at("waypoints").get().values; + BOOST_CHECK(!waypoints.empty()); // the dataset has at least one nearest coordinate + + for (const auto &waypoint : waypoints) + { + const auto &waypoint_object = waypoint.get(); + const auto distance = waypoint_object.values.at("distance").get().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; - /* NearestParameters params; json::Object result; - const auto rc = osrm.Nearest(params, result); + BOOST_REQUIRE(rc == Status::Error); - BOOST_CHECK(rc == Status::Ok || rc == Status::Error); - */ + const auto code = result.values.at("code").get().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)); + + using namespace osrm; + + NearestParameters params; + params.coordinates.emplace_back(util::FloatLongitude{}, util::FloatLatitude{}); + params.coordinates.emplace_back(util::FloatLongitude{}, util::FloatLatitude{}); + + json::Object result; + const auto rc = osrm.Nearest(params, result); + BOOST_REQUIRE(rc == Status::Error); + + const auto code = result.values.at("code").get().value; + BOOST_CHECK_EQUAL(code, "TooBig"); } BOOST_AUTO_TEST_SUITE_END()