tests/testthat/test-internal-helpers.R

test_that("array splitting preserves slices", {
  x <- array(seq_len(12), dim = c(2, 2, 3))
  parts <- lambdaTS:::split_array(x, along = 3)
  expect_length(parts, 3)
  expect_equal(dim(parts[[1]]), c(2, 2))
  expect_equal(parts[[2]], x[, , 2])
})

test_that("internal mapping supports purrr-style formulas", {
  expect_equal(unlist(lambdaTS:::map(1:3, ~ .x * 2)), c(2, 4, 6))
  expect_equal(unlist(lambdaTS:::map2(1:3, 4:6, ~ .x + .y)), c(5, 7, 9))
  expect_equal(unlist(lambdaTS:::pmap(list(1:2, 3:4), ~ ..1 + ..2)), c(4, 6))
})

test_that("Yeo-Johnson transformation is finite and invertible", {
  x <- c(-4, -1, 0, 1, 5)
  pars <- lambdaTS:::yjt_fun(x)
  transformed <- pars$predict_yjt(as.numeric(pars$scaled))
  restored <- lambdaTS:::inv_yjt(transformed, pars$lambda, pars$scaled)
  expect_true(all(is.finite(transformed)))
  expect_equal(as.numeric(restored), x, tolerance = 1e-5)
})

test_that("linear imputation removes internal missing values", {
  x <- c(1, NA, NA, 4)
  expect_equal(lambdaTS:::na_linear(x), c(1, 2, 3, 4))
})

test_that("business-day sequence excludes requested weekdays", {
  dates <- lambdaTS:::bizseq_internal(as.Date("2026-09-07"), 5,
                                      days_off = c("saturday", "sunday"))
  expect_length(dates, 5)
  expect_false(any(tolower(weekdays(dates)) %in% c("saturday", "sunday")))
})

Try the lambdaTS package in your browser

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

lambdaTS documentation built on Sept. 7, 2026, 9:08 a.m.