get intersection analysis unit, timezoner and updater unit tests to pass

get timzone unit tests to pass

get validation tests to pass

get updater and timezone unit test files to build with multiline string formatting

update validateFeature to validate polygon outterings and tzid

add tzid to all test fixtures of geojson features

add txid to test fixture

added tzid to hongkon test data but it already has timezone property
This commit is contained in:
Kajari Ghosh 2018-09-17 10:22:43 -04:00
parent 0940f23d9d
commit 0fa2c14500
8 changed files with 155 additions and 155 deletions

View File

@ -48,6 +48,15 @@ inline void validateFeature(const rapidjson::Value &feature)
{
throw osrm::util::exception("Feature has non-object properties member.");
}
else if (!feature.GetObject()["properties"].HasMember("tzid"))
{
throw osrm::util::exception("Feature is missing tzid member.");
}
else if (!feature["properties"]["tzid"].IsString())
{
throw osrm::util::exception("Feature has non-string tzid member.");
}
if (!feature.HasMember("geometry"))
{
throw osrm::util::exception("Feature is missing geometry member.");
@ -76,6 +85,11 @@ inline void validateFeature(const rapidjson::Value &feature)
const auto coord_array = feature["geometry"].GetObject()["coordinates"].GetArray();
if (coord_array.Empty())
throw osrm::util::exception("Feature geometry coordinates member is empty.");
if (feature["geometry"].GetObject()["type"] == "polygon" && coord_array[0].IsArray() &&
coord_array[0][0].IsNumber())
throw osrm::util::exception(
"Feature geometry coordinates of type Polygon is missing outterring.");
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,7 @@
"features": [ {
"type": "Feature",
"properties": {
"tzid": "Europe/Berlin",
"driving_side": "left",
"answer": 42,
"boolean": true,

View File

@ -1,4 +1,4 @@
// #include "extractor/intersection/intersection_analysis.hpp"
#include "extractor/intersection/intersection_analysis.hpp"
#include "extractor/graph_compressor.hpp"
@ -47,6 +47,7 @@ BOOST_AUTO_TEST_CASE(simple_intersection_connectivity)
to,
1,
1,
1,
GeometryID{0, false},
!allowed,
NodeBasedEdgeClassification(),
@ -169,12 +170,12 @@ BOOST_AUTO_TEST_CASE(roundabout_intersection_connectivity)
// 0
// ↙ ↑ ↘
// 4 5 6
const auto unit_edge = [](const NodeID from, const NodeID to, bool allowed, bool roundabout)
{
const auto unit_edge = [](const NodeID from, const NodeID to, bool allowed, bool roundabout) {
return InputEdge{from,
to,
1,
1,
1,
GeometryID{0, false},
!allowed,
NodeBasedEdgeClassification{
@ -278,7 +279,7 @@ BOOST_AUTO_TEST_CASE(skip_degree_two_nodes)
//
const auto unit_edge = [](const NodeID from, const NodeID to, bool allowed) {
return InputEdge{
from, to, 1, 1, GeometryID{0, false}, !allowed, NodeBasedEdgeClassification{}, 0};
from, to, 1, 1, 1, GeometryID{0, false}, !allowed, NodeBasedEdgeClassification{}, 0};
};
std::vector<InputEdge> edges = {unit_edge(0, 1, true), // 0
unit_edge(1, 0, true),

View File

@ -30,26 +30,28 @@ struct LocationDataFixture
BOOST_AUTO_TEST_CASE(polygon_tests)
{
LocationDataFixture fixture(R"json({
"type": "FeatureCollection",
"features": [
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"tzid" : "Europe/Berlin",
"answer": 42
},
"geometry": { "type": "Polygon", "coordinates": [
[ [3, 0], [1, 1], [0, 3], [-1, 1], [-3, 0], [-1, -1], [0, -3], [1, -1], [3, 0] ],
[ [1, 0], [0, 1], [-1, 0], [0, -1], [1, 0] ]
] }
},
{
},
{
"type": "Feature",
"properties": {
"tzid" : "Europe/Berlin",
"answer": true
},
"geometry": { "type": "Polygon", "coordinates": [ [ [0, 10], [3, 5], [1, 5], [10, 0], [-1, 5], [-3, 5], [0, 10] ] ] }
}
]})json");
}
]})json");
LocationDependentData data({fixture.temporary_file});
@ -77,7 +79,8 @@ BOOST_AUTO_TEST_CASE(multy_polygon_tests)
{
"type": "Feature",
"properties": {
"answer": 42
"answer": 42,
"tzid" : "Europe/Berlin"
},
"geometry": { "type": "MultiPolygon", "coordinates": [
[ [ [1, 0], [0, 1], [-1, 0], [0, -1], [1, 0] ] ],
@ -103,17 +106,17 @@ BOOST_AUTO_TEST_CASE(polygon_merging_tests)
"features": [
{
"type": "Feature",
"properties": { "answer": "a" },
"properties": { "tzid" : "Europe/Berlin", "answer": "a" },
"geometry": { "type": "Polygon", "coordinates": [ [ [3, 3], [-3, 3], [-3, -3], [3, -3], [3, 3] ] ] }
},
{
"type": "Feature",
"properties": { "answer": "b" },
"properties": { "tzid" : "Europe/Berlin", "answer": "b" },
"geometry": { "type": "Polygon", "coordinates": [ [ [7, 3], [1, 3], [1, -3], [7, -3], [7, 3] ] ] }
},
{
"type": "Feature",
"properties": { "answer": "c" },
"properties": { "tzid" : "Europe/Berlin", "answer": "c" },
"geometry": { "type": "Polygon", "coordinates": [ [ [8, 3], [2, 3], [2, -3], [8, -3], [8, 3] ] ] }
}
]})json");
@ -149,7 +152,7 @@ BOOST_AUTO_TEST_CASE(staircase_polygon)
"features": [
{
"type": "Feature",
"properties": { "answer": "a" },
"properties": { "tzid" : "Europe/Berlin", "answer": "a" },
"geometry": { "type": "Polygon", "coordinates": [ [ [0, 0], [3, 0], [3, 3], [2, 3], [2, 2], [1, 2], [1, 1], [0, 1], [0, 0] ] ] }
}
]})json");

View File

@ -4,7 +4,7 @@
{
"type": "Feature",
"properties": {
"TZID": "Europe\\/Berlin"
"tzid": "Europe\\/Berlin"
},
"geometry": {
"type": "Polygon",

View File

@ -12,50 +12,37 @@ using namespace osrm::updater;
BOOST_AUTO_TEST_CASE(timezoner_test)
{
const char json[] =
"{ \"type\" : \"FeatureCollection\", \"features\": ["
"{ \"type\" : \"Feature\","
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\":
\"polygon\", "
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
"48.88277], [8.57757, 49.07206], [8.28369, "
"49.07206], [8.28369, 48.88277]]] }} ]}";
auto json = R"({ "type" : "FeatureCollection", "features": [{ "type" :
"Feature", "properties" : { "tzid" : "Europe/Berlin"},
"geometry" : { "type" : "polygon", "coordinates":
[[[8.28369,48.88277], [8.57757, 48.88277], [8.57757, 49.07206], [8.28369,49.07206], [8.28369, 48.88277]]] }} ]} )";
std::time_t now = time(0);
BOOST_CHECK_NO_THROW(Timezoner tz(json, now));
boost::filesystem::path test_path(TEST_DATA_DIR "/test.geojson");
BOOST_CHECK_NO_THROW(Timezoner tz(test_path, now));
missing opening bracket
const char bad[] =
"\"type\" : \"FeatureCollection\", \"features\": ["
"{ \"type\" : \"Feature\","
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\":
\"polygon\", "
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
"48.88277], [8.57757, 49.07206], [8.28369, "
"49.07206], [8.28369, 48.88277]]] }} ]}";
// missing opening bracket
auto bad = R"({ "type" : "FeatureCollection", "features": [{ "type" :
"Feature","properties" : { "TZID" : "Europe/Berlin"}, "geometry"
: { "type":"polygon", "coordinates": [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369, 49.07206], [8.28369, 48.88277]]]
}} ]})";
BOOST_CHECK_THROW(Timezoner tz(bad, now), util::exception);
missing/malformed FeatureCollection type field
const char missing_type[] =
"{ \"FeatureCollection\", \"features\": ["
"{ \"type\" : \"Feature\","
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\":
\"polygon\", "
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
"48.88277], [8.57757, 49.07206], [8.28369, "
"49.07206], [8.28369, 48.88277]]] }} ]}";
// missing / malformed FeatureCollection type field
auto missing_type = R"({ "FeatureCollection", "features": [{ "type" :
"Feature","properties" : { "TZID" : "Europe/Berlin"},
"geometry" : { "type":"polygon", "coordinates":
[[[8.28369,48.88277], [8.57757, 48.88277], [8.57757, 49.07206],
[8.28369, 49.07206], [8.28369, 48.88277]]] }} ]})";
BOOST_CHECK_THROW(Timezoner tz(missing_type, now), util::exception);
const char missing_featc[] =
"{ \"type\" : \"Collection\", \"features\": ["
"{ \"type\" : \"Feature\","
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\":
\"polygon\", "
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
"48.88277], [8.57757, 49.07206], [8.28369, "
"49.07206], [8.28369, 48.88277]]] }} ]}";
auto missing_featc = R"({ "type" : "Collection", "features": [{ "type" :
"Feature","properties" : { "TZID" : "Europe/Berlin"},
"geometry" : { "type":"polygon", "coordinates":
[[[8.28369,48.88277], [8.57757, 48.88277], [8.57757, 49.07206],
[8.28369, 49.07206], [8.28369, 48.88277]]] }} ]})";
BOOST_CHECK_THROW(Timezoner tz(missing_featc, now), util::exception);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -29,116 +29,110 @@ BOOST_AUTO_TEST_CASE(timezone_coordinate_validation_test)
BOOST_AUTO_TEST_CASE(timezone_validation_test)
{
char json[] =
"{ \"type\" : \"Feature\","
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": \"polygon\", "
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
"48.88277], [8.57757, 49.07206], [8.28369, "
"49.07206], [8.28369, 48.88277]]] }}";
auto json =
R"({ "type" : "Feature",
"properties" : { "tzid" : "Europe/Berlin"}, "geometry" : { "type": "polygon",
"coordinates": [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]]] }})";
rapidjson::Document doc;
doc.Parse(json);
BOOST_CHECK_NO_THROW(util::validateFeature(doc));
char missing_type[] = "{\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { "
"\"type\": \"polygon\", "
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
"48.88277], [8.57757, 49.07206], [8.28369, "
"49.07206], [8.28369, 48.88277]]] }}";
auto missing_type = R"({"properties" : { "tzid" : "Europe/Berlin"}, "geometry" : {
"type": "polygon",
"coordinates": [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]]] }})";
doc.Parse(missing_type);
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
char missing_props[] =
"{ \"type\" : \"Feature\","
"\"props\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": \"polygon\", "
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
"48.88277], [8.57757, 49.07206], [8.28369, "
"49.07206], [8.28369, 48.88277]]] }}";
auto missing_props =
R"({ "type" : "Feature",
"props" : { "tzid" : "Europe/Berlin"}, "geometry" : { "type": "polygon",
"coordinates": [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]]] }})";
doc.Parse(missing_props);
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
char nonobj_props[] =
"{ \"type\" : \"Feature\","
"\"properties\" : [ \"TZID\", \"Europe/Berlin\"], \"geometry\" : { \"type\": \"polygon\", "
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
"48.88277], [8.57757, 49.07206], [8.28369, "
"49.07206], [8.28369, 48.88277]]] }}";
auto nonobj_props =
R"({ "type" : "Feature",
"properties" : [ "tzid", "Europe/Berlin"], "geometry" : { "type": "polygon",
"coordinates": [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]]] }})";
doc.Parse(nonobj_props);
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
char missing_tzid[] = "{ \"type\" : \"Feature\","
"\"properties\" : { }, \"geometry\" : { \"type\": \"polygon\", "
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
"48.88277], [8.57757, 49.07206], [8.28369, "
"49.07206], [8.28369, 48.88277]]] }}";
auto missing_tzid = R"({ "type" : "Feature",
"properties" : { }, "geometry" : { "type": "polygon",
"coordinates": [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]]] }})";
doc.Parse(missing_tzid);
// BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
// char tzid_err[] = "{ \"type\" : \"Feature\","
// "\"properties\" : { \"TZID\" : []}, \"geometry\" : { \"type\": \"polygon\",
// "
// "\"coordinates\": [[[8.28369,48.88277], [8.57757, "
// "48.88277], [8.57757, 49.07206], [8.28369, "
// "49.07206], [8.28369, 48.88277]]] }}";
// doc.Parse(tzid_err);
// BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
auto tzid_err = R"({ "type" : "Feature",
"properties" : { "tzid" : []}, "geometry" : { "type": "polygon",
"coordinates": [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]]] }})";
doc.Parse(tzid_err);
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
// char missing_geom[] = "{ \"type\" : \"Feature\","
// "\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometries\" : { "
// "\"type\": \"polygon\", "
// "\"coordinates\": [[[8.28369,48.88277], [8.57757, "
// "48.88277], [8.57757, 49.07206], [8.28369, "
// "49.07206], [8.28369, 48.88277]]] }}";
// doc.Parse(missing_geom);
// BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
auto missing_geom = R"({ "type" : "Feature",
"properties" : { "tzid" : "Europe/Berlin"}, "geometries" : {
"type": "polygon",
"coordinates": [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]]] }})";
doc.Parse(missing_geom);
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
// char nonobj_geom[] =
// "{ \"type\" : \"Feature\","
// "\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : [ \"type\",
// \"polygon\", "
// "\"coordinates\", [[[8.28369,48.88277], [8.57757, "
// "48.88277], [8.57757, 49.07206], [8.28369, "
// "49.07206], [8.28369, 48.88277]]] ]}";
// doc.Parse(nonobj_geom);
// BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
auto nonobj_geom =
R"({ "type" : "Feature",
"properties" : { "tzid" : "Europe/Berlin"}, "geometry" : [ "type",
"polygon",
"coordinates", [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]]] ]})";
doc.Parse(nonobj_geom);
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
// char missing_geom_type[] = "{ \"type\" : \"Feature\","
// "\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" :
// { "
// "\"no_type\": \"polygon\", "
// "\"coordinates\": [[[8.28369,48.88277], [8.57757, "
// "48.88277], [8.57757, 49.07206], [8.28369, "
// "49.07206], [8.28369, 48.88277]]] }}";
// doc.Parse(missing_geom_type);
// BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
auto missing_geom_type = R"({ "type" : "Feature",
"properties" : { "tzid" : "Europe/Berlin"}, "geometry" : {
"no_type": "polygon",
"coordinates": [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]]] }})";
doc.Parse(missing_geom_type);
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
// char nonstring_geom_type[] = "{ \"type\" : \"Feature\","
// "\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\"
// : "
// "{ \"type\": [\"polygon\"], "
// "\"coordinates\": [[[8.28369,48.88277], [8.57757, "
// "48.88277], [8.57757, 49.07206], [8.28369, "
// "49.07206], [8.28369, 48.88277]]] }}";
// doc.Parse(nonstring_geom_type);
// BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
auto nonstring_geom_type = R"({ "type" : "Feature",
"properties" : { "tzid" : "Europe/Berlin"}, "geometry" :
{ "type": ["polygon"], "
"coordinates": [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]]] }})";
doc.Parse(nonstring_geom_type);
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
// char missing_coords[] =
// "{ \"type\" : \"Feature\","
// "\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\":
// \"polygon\", "
// "\"coords\": [[[8.28369,48.88277], [8.57757, "
// "48.88277], [8.57757, 49.07206], [8.28369, "
// "49.07206], [8.28369, 48.88277]]] }}";
// doc.Parse(missing_coords);
// BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
auto missing_coords = R"({ "type" : "Feature",
"properties" : { "tzid" : "Europe/Berlin"}, "geometry" : { "type":
"polygon",
"coords": [[[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]]] }})";
doc.Parse(missing_coords);
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
// char missing_outerring[] =
// "{ \"type\" : \"Feature\","
// "\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\":
// \"polygon\", "
// "\"coordinates\": [[8.28369,48.88277], [8.57757, "
// "48.88277], [8.57757, 49.07206], [8.28369, "
// "49.07206], [8.28369, 48.88277]] }}";
// doc.Parse(missing_outerring);
// BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
auto missing_outerring = R"({ "type" : "Feature",
"properties" : { "tzid" : "Europe/Berlin"}, "geometry" : { "type": "polygon",
"coordinates": [[8.28369,48.88277], [8.57757,
48.88277], [8.57757, 49.07206], [8.28369,
49.07206], [8.28369, 48.88277]] }})";
doc.Parse(missing_outerring);
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
}
BOOST_AUTO_TEST_SUITE_END()