Skip to content

Commit

Permalink
silence warnings on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jayrobwilliams committed Jun 20, 2021
1 parent b682905 commit ee329a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
25 changes: 8 additions & 17 deletions tests/testthat/test-overlap.weight.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,20 @@ raster_t <- raster(nrows = 10, ncols = 10, xmn = 0, xmx = 10, ymn = 0, ymx = 10,
vals = 1:100, crs = CRS(st_crs(polys_t)$proj4string))

test_that("overlap.weight works with sfc_POLYGON", {
expect_equal(overlap.weight(raster_t, polys_t)[4,4], 28)
expect_equal(overlap.weight(raster_t, polys_t, warn = FALSE)[4,4], 28)
})

test_that("overlap.weight works with sf", {
expect_equal(overlap.weight(raster_t,
st_sf(data.frame(a = 1:2,
geometry = polys_t)))[4,4], 28)
})

test_that("overlap.weight works with SpatialPolygons", {
expect_equal(overlap.weight(raster_t, as(polys_t, 'Spatial'))[4,4], 28)
})

test_that("overlap.weight works with SpatialPolygonsDataFrame", {
expect_equal(overlap.weight(raster_t,
as(st_sf(data.frame(a = 1:2, geometry = polys_t)),
'Spatial'))[4,4], 28)
expect_equal(overlap.weight(raster_t, st_sf(data.frame(a = 1:2,
geometry = polys_t)),
warn = FALSE)[4,4], 28)
})

test_that("overlap.weight works with count", {
expect_equal(overlap.weight(raster_t, polys_t, count = TRUE)[4,4], 2)
expect_equal(overlap.weight(raster_t, polys_t, count = TRUE,
warn = FALSE)[4,4], 2)
})

test_that("overlap.weight works silently", {
expect_silent(overlap.weight(raster_t, polys_t, warn = FALSE))
test_that("overlap.weight warns about different extents", {
expect_warning(overlap.weight(raster_t, polys_t, warn = TRUE))
})
5 changes: 0 additions & 5 deletions tests/testthat/test-pointpolydist.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ test_that("point.poly.dist works with arguments", {
tolerance = 1e-3)
})

test_that("point.poly.dist works with Spatial", {
expect_error(point.poly.dist(as_Spatial(points_t), poly_t), NA)
expect_error(point.poly.dist(points_t, as_Spatial(poly_t)), NA)
})

test_that("point.poly.dist works with projected CRS", {
expect_equal(point.poly.dist(points_t, projectUTM(poly_t)), 100201.5,
tolerance = 1e-3)
Expand Down
10 changes: 7 additions & 3 deletions tests/testthat/test-projectUTM.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ poly_t <- st_sfc(st_polygon(list(rbind(c(10,-10), c(10,-20), c(20,-20),
crs = st_crs('OGC:CRS84'))

test_that("projectUTM works with sfc_POLYGON", {
expect_equal(st_crs(projectUTM(st_cast(nc[1,], "POLYGON")))[["input"]],
expect_equal(st_crs(projectUTM(st_cast(st_geometry(nc[1,]),
"POLYGON")))[["input"]],
"+proj=utm +zone=17")
})

Expand All @@ -15,11 +16,14 @@ test_that("projectUTM works with sfc_MULTIPOLYGON", {


test_that("projectUTM works with sfc_POINT", {
expect_equal(st_crs(projectUTM(st_centroid(nc)))[["input"]], "+proj=utm +zone=17")
expect_equal(st_crs(projectUTM(st_centroid(st_geometry(nc))))[["input"]],
"+proj=utm +zone=17")
})

test_that("projectUTM works with sfc_POINT", {
expect_equal(st_crs(projectUTM(st_cast(st_centroid(nc), 'MULTIPOINT')))[["input"]], "+proj=utm +zone=17")
expect_equal(st_crs(projectUTM(st_cast(st_centroid(st_geometry(nc)),
'MULTIPOINT')))[["input"]],
"+proj=utm +zone=17")
})

test_that("projectUTM works with southern latitude", {
Expand Down

0 comments on commit ee329a0

Please sign in to comment.