tests/testthat/helpers.R

testFormat <- function(fun)
{
  x <- rnorm(100)
  y <- fun(x)
  expect_equal(class(y), class(x))
  expect_equal(length(y), length(x))
  
  x <- ts(x)
  y <- fun(x)
  expect_equal(class(y), class(x))
  expect_equal(length(y), length(x))
  expect_equal(attr(y, "tsp"), attr(x, "tsp"))
  
  X <- matrix(rnorm(1000), ncol = 10)
  Y <- fun(X)
  expect_equal(class(Y), class(X))
  expect_equal(nrow(Y), nrow(X))
  
  X <- ts(X)
  Y <- psi(X)
  expect_equal(class(Y), class(X))
  expect_equal(nrow(Y), nrow(X))
  expect_equal(attr(Y, "tsp"), attr(X, "tsp"))
}

testStructure <- function(fun, method)
{
  x <- rnorm(100)
  y <- fun(x, method = method)
  
  expect_true(is.list(y))
  expect_true(is(y$lrv, "list"))
  expect_equal(class(y), "htest")
  
  expect_true(all(c("alternative", "method", "data.name", "statistic", "p.value",
                    "cp.location", "lrv") %in% names(y)))
  expect_true(all(c("method", "param", "value") %in% names(y$lrv)))
}

Try the robcp package in your browser

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

robcp documentation built on Sept. 16, 2022, 5:05 p.m.