tests/testthat/test-RootLinearInterpolant.R

test_that("Check whether interpolant does what it's supposed to", {
  #We only work with increasing data in y, so no need to check when y is not increasing
  x <- c(1, 2, 3, 4)
  y <- c(3, 5, 9, 20)
  expect_equal(RootLinearInterpolant(x, y, y0 = 4), 1.5)
  expect_equal(RootLinearInterpolant(x, y, y0 = 7), 2.5)
  #check for unsorted
  rord <- sample(1:4)
  x <- x[rord]
  y <- y[rord]
  expect_equal(RootLinearInterpolant(x, y, y0 = 4), 1.5)
  expect_equal(RootLinearInterpolant(x, y, y0 = 7), 2.5)
  #Return NA when no inverse exists
  expect_equal(RootLinearInterpolant(x, y, y0 = 30), NA)
})

Try the success package in your browser

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

success documentation built on June 22, 2024, 10:19 a.m.