tests/testthat/test-trapbuilder.R

# test GRTS

library(secr)
library(sf)

## to avoid ASAN/UBSAN errors on CRAN, following advice of Kevin Ushey
## e.g. https://github.com/RcppCore/RcppParallel/issues/169
Sys.setenv(RCPP_PARALLEL_BACKEND = "tinythread")

shapefilename <- system.file("extdata/OVforest.shp", package = "secr")
OVforest <- sf::st_read(shapefilename, quiet = TRUE)[1:2,1]

test_that("method = 'SRS' works", {
    set.seed(1235)
    # simple random sample
    expect_silent(sample0 <- trap.builder(n = 32, region = OVforest, method = 'SRS'))
    expect_equal(spacing(sample0), 76.3612953003, tolerance = 1e-4, check.attributes = FALSE)
})


test_that("method = 'GRTS' works", {
    set.seed(1235)
    # GRTS sample
    expect_silent(sample1 <- trap.builder(n = 32, region = OVforest, method = 'GRTS'))
    expect_equal(spacing(sample1), 94.7225747307, tolerance = 1e-4, check.attributes = FALSE)
})

Try the secr package in your browser

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

secr documentation built on Oct. 18, 2023, 1:07 a.m.