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')
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.