tests/testthat/test-sphere.R

test_that("sphere() works", {
  set.seed(20240412)
  testthat::expect_snapshot(sphere(
    radius = 1, resolution = 20, num_noise = 3,
    min_n = -0.05, max_n = 0.05
  ))

  testthat::expect_error(sphere(
    radius = -1, resolution = 20, num_noise = 3,
    min_n = -0.05, max_n = 0.05
  ))
  testthat::expect_error(sphere(
    radius = 1, resolution = -20, num_noise = 3,
    min_n = -0.05, max_n = 0.05
  ))
  testthat::expect_error(sphere(
    radius = 1, resolution = 20, num_noise = -3,
    min_n = -0.05, max_n = 0.05
  ))
  testthat::expect_error(sphere(
    resolution = 20, num_noise = 3,
    min_n = -0.05, max_n = 0.05
  ))
  testthat::expect_error(sphere(
    radius = 1, num_noise = 3,
    min_n = -0.05, max_n = 0.05
  ))
  testthat::expect_snapshot(sphere(radius = 1, resolution = 20, num_noise = 0))
  testthat::expect_error(sphere(
    radius = 1, resolution = 20, num_noise = 3,
    max_n = 0.05
  ))
  testthat::expect_error(sphere(
    radius = -1, resolution = 20, num_noise = 3,
    min_n = -0.05
  ))
})

test_that("diff_sphere() works", {
  set.seed(20240412)
  testthat::expect_snapshot(diff_sphere(
    n = 390, num_noise = 4, min_n = -0.05,
    max_n = 0.05
  ))

  testthat::expect_error(diff_sphere(
    n = -390, num_noise = 4, min_n = -0.05,
    max_n = 0.05
  ))
  testthat::expect_error(diff_sphere(
    n = 390, num_noise = -4, min_n = -0.05,
    max_n = 0.05
  ))
  testthat::expect_snapshot(diff_sphere(n = 390, num_noise = 0))
  testthat::expect_error(diff_sphere(n = 390, num_noise = 4, min_n = -0.05))
  testthat::expect_error(diff_sphere(n = 390, num_noise = 4, max_n = 0.05))
})

Try the cardinalR package in your browser

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

cardinalR documentation built on May 29, 2024, 4:37 a.m.