tests/testthat/test-lagged_correlations.R

test_that("function works", {

  x <- rnorm(100)
  y <- rnorm(100)
  n <- length(x)

  expect_equal(lagged_correlations(x, y)[1], cor(x,y))
  expect_equal(abs(lagged_correlations(x, y)[n-1]), 1)

})

test_that("catches error", {

  x <- rnorm(100)
  y <- rnorm(99)

  expect_error(lagged_correlations(x, y), "lengths of x and y differ")

})

test_that("there are no NA's", {

  x <- rnorm(100)
  y <- rnorm(100)

  expect_equal(sum(is.na(lagged_correlations(x, y))), 0)

})

test_that("function returns numeric vector", {

  x <- rnorm(100)
  y <- rnorm(100)

  expect_type(lagged_correlations(x, y), 'double')

})
pawel-wieczynski/PolishStock documentation built on March 23, 2022, 3:32 p.m.