Skip to content

Commit 204dd2c

Browse files
committed
Made tests more explanatory, and added test checking for correlations themselves.
1 parent 160c530 commit 204dd2c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tests/testthat/test-correlation.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library(tibble)
22

3-
test_that("epi_cor throws an error for a non-epi df for its first argument",{
3+
test_that("epi_cor throws an error for a non-epi_df for its first argument",{
44
expect_error(epi_cor(1:10,1,1))
55
expect_error(epi_cor(data.frame(x=1:10),1,1))
66
})
@@ -10,17 +10,24 @@ test_that("epi_cor requires two var arguments, var1 and var2",{
1010
expect_error(epi_cor(archive_cases_dv_subset$DT,var1=1))
1111
})
1212

13-
test_that("epi_cor functions as it should",{
13+
test_that("epi_cor functions as intended",{
1414
expect_equal(epi_cor(x = jhu_csse_daily_subset,
1515
var1 = case_rate_7d_av,
1616
var2 = death_rate_7d_av,
1717
cor_by = geo_value,
1818
dt1 = -2)[1],
1919
tibble(geo_value = unique(jhu_csse_daily_subset$geo_value))
2020
)
21+
22+
edf <- as_epi_df(data.frame(geo_value=rep("asdf",20),
23+
time_value=as.Date("2020-01-01") + 1:20,
24+
pos=1:20,
25+
neg=-(1:20)))
26+
expect_equal(epi_cor(edf, pos, pos)[[2]],1)
27+
expect_equal(epi_cor(edf, pos, neg)[[2]],-1)
2128
})
2229

23-
test_that("shift works as it should",{
30+
test_that("shift works as intended",{
2431
expect_identical(shift(1:100,1),dplyr::lead(1:100))
2532
expect_identical(shift(1:100,0),1:100)
2633
expect_identical(shift(1:100,-1),dplyr::lag(1:100))

0 commit comments

Comments
 (0)