tests/testthat/test-remove_burn_ins.R

context("remove_burn_ins")

test_that("normal use", {

  # Remove first ten percent
  v <- data.frame(x = seq(1, 10), y = seq(11, 20))
  w <- remove_burn_ins(trace = v, burn_in_fraction  = 0.1)
  expected <- data.frame(x = seq(2, 10), y = seq(12, 20))
  names(expected) <- names(w)

  expect_true(all(w == expected))
})

test_that("100 percent burn-in", {

  # Remove first ten percent
  v <- data.frame(x = seq(1, 10), y = seq(11, 20))
  w <- tracerer::remove_burn_ins(trace = v, burn_in_fraction  = 1.0)
  testthat::expect_equal(nrow(w), 0)
})


test_that("remove_burn_ins: abuse", {

  v <- data.frame(x = seq(1, 10), y = seq(11, 20))

  expect_error(
    remove_burn_ins(traces = v, burn_in_fraction  = -0.1),
    "'burn_in_fraction' must be at least zero"
  )

  expect_error(
    remove_burn_ins(traces = v, burn_in_fraction  = 1.1),
    "'burn_in_fraction' must be one at most"
  )

  expect_error(
    remove_burn_ins(traces = "not a valid trace", burn_in_fraction  = 0.1),
    "'traces' must be a data.frame"
  )

})
richelbilderbeek/tracerer documentation built on Oct. 2, 2023, 7:32 a.m.