tests/testthat/test_misc.R

test_that('closest_to_target works', {
  expect_equal(closest_to_target(c(0.1, 0.2, 0.3), 0.05), 1)
  expect_equal(closest_to_target(c(0.1, 0.2, 0.3), 0.22), 2)
  expect_equal(closest_to_target(c(0.1, 0.2, 0.3), -0.05), 1)
  expect_equal(closest_to_target(c(0.1, 0.2, 0.3), 8), 3)
})

Try the trialr package in your browser

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

trialr documentation built on April 1, 2023, 12:03 a.m.