tests/testthat/test_helpers.R

test_that("moving average works", {
  testthat::expect_length(moving_average(timeseries = c(1, 1, 1, 1), window = 2), n = 4)
  testthat::expect_equal(moving_average(timeseries = c(1, 1, 1, 1), window = 2), c(NA, 1, 1, NA))
  testthat::expect_error(moving_average(timeseries = c(1, 1, 1, 1), window = 1))
  testthat::expect_error(moving_average(timeseries = c(1, 1, 1, 1), window = 5))
})

test_that("normalizing a vector works", {
  testthat::expect_length(normalize_data(vec = c(1, 1, 1, 1)), n = 4)
  testthat::expect_equal(normalize_data(vec = seq(0, 5)), seq(0, 1, 0.2))
})

Try the swaRmverse package in your browser

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

swaRmverse documentation built on Oct. 10, 2024, 5:08 p.m.