Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Mar 31, 2024
1 parent 5515f3c commit bcb241d
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/testthat/test-wkb.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,69 @@ test_that("st_as_sfc() honors crs argument", {
expect_identical(st_as_sfc(list, crs = 2056), st_as_sfc(wkb, crs = 2056))
expect_identical(st_as_sfc(blob, crs = 2056), st_as_sfc(wkb, crs = 2056))
})

test_that("st_as_sfc() for WKB can promote_to_multi for multipoint + point", {
sfc_mixed = st_sfc(
st_point(),
st_point(c(2, 3)),
st_multipoint()
)

wkb_mixed = st_as_binary(sfc_mixed)

expect_identical(
st_as_sfc(wkb_mixed, promote_to_multi = FALSE),
sfc_mixed
)

expect_identical(
st_as_sfc(wkb_mixed, promote_to_multi = TRUE),
st_cast(sfc_mixed, "MULTIPOINT")
)
})

test_that("st_as_sfc() for WKB can promote_to_multi for multilinestring + linestring", {
sfc_mixed = st_sfc(
st_linestring(),
st_linestring(rbind(c(2, 3), c(4, 5))),
st_multilinestring()
)

wkb_mixed = st_as_binary(sfc_mixed)

expect_identical(
st_as_sfc(wkb_mixed, promote_to_multi = FALSE),
sfc_mixed
)

# st_as_sfc() assigns different attribute order than st_cast, but we ony care
# about whether the geometries are correct
expect_equal(
st_as_sfc(wkb_mixed, promote_to_multi = TRUE),
st_cast(sfc_mixed, "MULTILINESTRING"),
ignore_attr = TRUE
)
})

test_that("st_as_sfc() for WKB can promote_to_multi for multipolygon + polygon", {
sfc_mixed = st_sfc(
st_polygon(),
st_polygon(list(rbind(c(0, 0), c(1, 0), c(0, 1), c(0, 0)))),
st_multipolygon()
)

wkb_mixed = st_as_binary(sfc_mixed)

expect_identical(
st_as_sfc(wkb_mixed, promote_to_multi = FALSE),
sfc_mixed
)

# st_as_sfc() assigns different attribute order than st_cast, but we ony care
# about whether the geometries are correct
expect_equal(
st_as_sfc(wkb_mixed, promote_to_multi = TRUE),
st_cast(sfc_mixed, "MULTILINESTRING"),
ignore_attr = TRUE
)
})

0 comments on commit bcb241d

Please sign in to comment.