tests/testthat/test-balance_points.R

# context("test-balance_points")

test_that("balance_points works for integer n", {

  input <- spatstat.random::rpoispp(lambda = 100)

  result <- balance_points(pattern = input, n = 110, verbose = FALSE)

  expect_equal(object = result$n, expected = 110)
})

test_that("balance_points works for ppp n", {

  input <- spatstat.random::rpoispp(lambda = 100)
  input_b <- spatstat.random::rpoispp(lambda = 100)

  result <- balance_points(pattern = input, n = input_b, verbose = FALSE)

  expect_equal(object = result$n, expected = input_b$n)
})

test_that("balance_points returns error", {

  input <- spatstat.random::rpoispp(lambda = 100)

  expect_error(object = balance_points(pattern = input, n = 50.5, verbose = FALSE),
               regexp = "n must be either integer or ppp.")
})

test_that("balance_points returns warning", {

  input <- spatstat.random::rpoispp(lambda = 100)

  expect_warning(object = balance_points(pattern = input, n = 20),
                 regexp = "Differences between pattern and n more than 0.33.")
})

Try the onpoint package in your browser

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

onpoint documentation built on Sept. 17, 2024, 5:09 p.m.