Unpack paths and return total distance in matrix plugin for CH (#4990)

This commit is contained in:
Kajari Ghosh
2018-04-20 18:18:55 -04:00
committed by GitHub
parent 9970b7d580
commit 14860b62e9
38 changed files with 1886 additions and 538 deletions
+14 -1
View File
@@ -27,6 +27,7 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix)
params.coordinates.push_back(get_dummy_location());
params.sources.push_back(0);
params.destinations.push_back(2);
params.annotations = TableParameters::AnnotationsType::All;
json::Object result;
@@ -46,6 +47,18 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix)
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 = 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());
}
// 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());
@@ -73,7 +86,6 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix)
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);
@@ -119,6 +131,7 @@ BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix)
params.coordinates.push_back(get_dummy_location());
params.coordinates.push_back(get_dummy_location());
params.coordinates.push_back(get_dummy_location());
params.annotations = TableParameters::AnnotationsType::Duration;
json::Object result;
+3 -2
View File
@@ -56,7 +56,9 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
}
NodeForwardRange GetUncompressedForwardGeometry(const EdgeID /* id */) const override
{
return {};
static NodeID data[] = {0, 1, 2, 3};
static extractor::SegmentDataView::SegmentNodeVector nodes(data, 4);
return boost::make_iterator_range(nodes.cbegin(), nodes.cend());
}
NodeReverseRange GetUncompressedReverseGeometry(const EdgeID id) const override
{
@@ -73,7 +75,6 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
{
return WeightReverseRange(GetUncompressedForwardWeights(id));
}
DurationForwardRange GetUncompressedForwardDurations(const EdgeID /*id*/) const override
{
static std::uint64_t data[] = {1, 2, 3};
+46 -6
View File
@@ -86,11 +86,13 @@ BOOST_AUTO_TEST_CASE(invalid_table_urls)
testInvalidOptions<TableParameters>("1,2;3,4?sources=1&destinations=1&bla=foo"), 32UL);
BOOST_CHECK_EQUAL(testInvalidOptions<TableParameters>("1,2;3,4?sources=foo"), 16UL);
BOOST_CHECK_EQUAL(testInvalidOptions<TableParameters>("1,2;3,4?destinations=foo"), 21UL);
BOOST_CHECK_EQUAL(
testInvalidOptions<TableParameters>("1,2;3,4?sources=all&destinations=all&annotations=bla"),
49UL);
}
BOOST_AUTO_TEST_CASE(valid_route_hint)
{
engine::PhantomNode reference_node;
reference_node.input_location =
util::Coordinate(util::FloatLongitude{7.432251}, util::FloatLatitude{43.745995});
@@ -284,6 +286,7 @@ BOOST_AUTO_TEST_CASE(valid_route_urls)
{util::FloatLongitude{3}, util::FloatLatitude{4}},
{util::FloatLongitude{5}, util::FloatLatitude{6}},
{util::FloatLongitude{7}, util::FloatLatitude{8}}};
engine::PhantomNode phantom_3;
phantom_3.input_location = coords_3[0];
engine::PhantomNode phantom_4;
@@ -379,11 +382,11 @@ BOOST_AUTO_TEST_CASE(valid_route_urls)
"overview=simplified&annotations=duration,weight,nodes");
BOOST_CHECK(result_16);
BOOST_CHECK_EQUAL(reference_16.geometries, result_16->geometries);
BOOST_CHECK_EQUAL(
static_cast<bool>(result_2->annotations_type & (RouteParameters::AnnotationsType::Weight |
RouteParameters::AnnotationsType::Duration |
RouteParameters::AnnotationsType::Nodes)),
true);
BOOST_CHECK_EQUAL(static_cast<bool>(result_16->annotations_type &
(RouteParameters::AnnotationsType::Weight |
RouteParameters::AnnotationsType::Duration |
RouteParameters::AnnotationsType::Nodes)),
true);
BOOST_CHECK_EQUAL(result_16->annotations, true);
// parse all annotations correctly
@@ -523,6 +526,43 @@ BOOST_AUTO_TEST_CASE(valid_table_urls)
CHECK_EQUAL_RANGE(reference_1.radiuses, result_3->radiuses);
CHECK_EQUAL_RANGE(reference_1.approaches, result_3->approaches);
CHECK_EQUAL_RANGE(reference_1.coordinates, result_3->coordinates);
TableParameters reference_4{};
reference_4.coordinates = coords_1;
auto result_4 = parseParameters<TableParameters>(
"1,2;3,4?sources=all&destinations=all&annotations=duration");
BOOST_CHECK(result_4);
BOOST_CHECK_EQUAL(result_4->annotations & (TableParameters::AnnotationsType::Distance |
TableParameters::AnnotationsType::Duration),
true);
CHECK_EQUAL_RANGE(reference_4.sources, result_4->sources);
CHECK_EQUAL_RANGE(reference_4.destinations, result_4->destinations);
TableParameters reference_5{};
reference_5.coordinates = coords_1;
auto result_5 = parseParameters<TableParameters>(
"1,2;3,4?sources=all&destinations=all&annotations=duration");
BOOST_CHECK(result_5);
BOOST_CHECK_EQUAL(result_5->annotations & TableParameters::AnnotationsType::Duration, true);
CHECK_EQUAL_RANGE(reference_5.sources, result_5->sources);
CHECK_EQUAL_RANGE(reference_5.destinations, result_5->destinations);
TableParameters reference_6{};
reference_6.coordinates = coords_1;
auto result_6 = parseParameters<TableParameters>(
"1,2;3,4?sources=all&destinations=all&annotations=distance");
BOOST_CHECK(result_6);
BOOST_CHECK_EQUAL(result_6->annotations & TableParameters::AnnotationsType::Distance, true);
CHECK_EQUAL_RANGE(reference_6.sources, result_6->sources);
CHECK_EQUAL_RANGE(reference_6.destinations, result_6->destinations);
TableParameters reference_7{};
reference_7.coordinates = coords_1;
auto result_7 = parseParameters<TableParameters>("1,2;3,4?annotations=distance");
BOOST_CHECK(result_7);
BOOST_CHECK_EQUAL(result_7->annotations & TableParameters::AnnotationsType::Distance, true);
CHECK_EQUAL_RANGE(reference_7.sources, result_7->sources);
CHECK_EQUAL_RANGE(reference_7.destinations, result_7->destinations);
}
BOOST_AUTO_TEST_CASE(valid_match_urls)
+3
View File
@@ -220,6 +220,7 @@ BOOST_AUTO_TEST_CASE(packed_weights_container_with_type_erasure)
auto forward = boost::make_iterator_range(vector.begin() + 1, vector.begin() + 6);
auto forward_any = WeightsAnyRange(forward.begin(), forward.end());
CHECK_EQUAL_RANGE(forward, 1, 2, 3, 4, 5);
CHECK_EQUAL_RANGE(forward_any, 1, 2, 3, 4, 5);
@@ -243,11 +244,13 @@ BOOST_AUTO_TEST_CASE(packed_weights_view_with_type_erasure)
auto forward = boost::make_iterator_range(view.begin() + 1, view.begin() + 4);
auto forward_any = WeightsAnyRange(forward.begin(), forward.end());
CHECK_EQUAL_RANGE(forward, 1, 2, 3);
CHECK_EQUAL_RANGE(forward_any, 1, 2, 3);
auto reverse = boost::adaptors::reverse(forward);
auto reverse_any = WeightsAnyRange(reverse);
CHECK_EQUAL_RANGE(reverse, 3, 2, 1);
CHECK_EQUAL_RANGE(reverse_any, 3, 2, 1);
}