Skip to content

Commit 948cedb

Browse files
authored
Merge pull request #1707 from joto/geom-test-lines
Add some tests for line geometry creation from OSM data
2 parents 5575577 + c7cd13e commit 948cedb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/test-geom-lines.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,45 @@ TEST_CASE("line geometry", "[NoDB]")
4848
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{1.5, 1.5}});
4949
}
5050

51+
TEST_CASE("create_linestring from OSM data", "[NoDB]")
52+
{
53+
test_buffer_t buffer;
54+
buffer.add_node("w20 Nn1x1y1,n2x2y2");
55+
56+
auto const geom =
57+
geom::create_linestring(buffer.buffer().get<osmium::Way>(0));
58+
59+
REQUIRE(geom.is_linestring());
60+
REQUIRE(geometry_type(geom) == "LINESTRING");
61+
REQUIRE(num_geometries(geom) == 1);
62+
REQUIRE(area(geom) == Approx(0.0));
63+
REQUIRE(geom.get<geom::linestring_t>() ==
64+
geom::linestring_t{{1, 1}, {2, 2}});
65+
REQUIRE(centroid(geom) == geom::geometry_t{geom::point_t{1.5, 1.5}});
66+
}
67+
68+
TEST_CASE("create_linestring from OSM data without locations", "[NoDB]")
69+
{
70+
test_buffer_t buffer;
71+
buffer.add_node("w20 Nn1,n2");
72+
73+
auto const geom =
74+
geom::create_linestring(buffer.buffer().get<osmium::Way>(0));
75+
76+
REQUIRE(geom.is_null());
77+
}
78+
79+
TEST_CASE("create_linestring from invalid OSM data", "[NoDB]")
80+
{
81+
test_buffer_t buffer;
82+
buffer.add_node("w20 Nn1x1y1");
83+
84+
auto const geom =
85+
geom::create_linestring(buffer.buffer().get<osmium::Way>(0));
86+
87+
REQUIRE(geom.is_null());
88+
}
89+
5190
TEST_CASE("geom::segmentize w/o split", "[NoDB]")
5291
{
5392
geom::linestring_t const line{{0, 0}, {1, 2}, {2, 2}};

0 commit comments

Comments
 (0)