tests/testthat/test-mask.R

test_that("the mask marks the points inside the polygon", {
    skip_if_not_installed("sf")
    sq <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0), c(2, 0), c(2, 2),
                                              c(0, 2), c(0, 0)))), crs = 4326)
    m <- vol_mask(lon = c(-1, 1, 3), lat = c(-1, 1, 3), sq)
    expect_identical(dim(m), c(3L, 3L))
    expect_true(m[2, 2])
    expect_false(m[1, 1])
    expect_identical(sum(m), 1L)
})

test_that("the mask has one row per latitude and one column per longitude", {
    skip_if_not_installed("sf")
    sq <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0), c(9, 0), c(9, 9),
                                              c(0, 9), c(0, 0)))), crs = 4326)
    m <- vol_mask(lon = seq(1, 8, by = 1), lat = seq(1, 5, by = 1), sq)
    expect_identical(dim(m), c(5L, 8L))
    expect_true(all(m))
})

Try the volumr package in your browser

Any scripts or data that you put into this service are public.

volumr documentation built on Dec. 2, 2026, 5:07 p.m.