Skip to content

Commit 6a8172a

Browse files
committed
More WIP on tests
1 parent 6dcf722 commit 6a8172a

File tree

1 file changed

+69
-9
lines changed

1 file changed

+69
-9
lines changed

tests/testthat/test-epi_slide_opt_archive.R

+69-9
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,80 @@ test_that("epi_slide_opt_archive_one_epikey works as expected", {
5555
f <- purrr::partial(data.table::frollmean, algo = "exact")
5656

5757
result <- updates %>%
58-
epi_slide_opt_archive_one_epikey("value", f, "data.table", 2L, 0L, "day", "slide_value")
59-
60-
expect_equal(
61-
result %>% lapply(function(x) {
58+
epi_slide_opt_archive_one_epikey("value", f, "data.table", 2L, 0L, "day", "slide_value") %>%
59+
lapply(function(x) {
6260
x %>%
6361
arrange(time_value) %>%
6462
select(version, time_value, everything())
6563
})
66-
,
67-
expected
68-
)
6964

70-
# TODO check about version nesting ordering
65+
expect_equal(result, expected)
66+
})
7167

68+
69+
test_that("epi_slide_opt.epi_archive is not confused by unique(DT$version) unsorted", {
70+
start_date <- as.Date("2020-01-01")
71+
tibble(
72+
geo_value = 1,
73+
time_value = start_date - 1 + 1:4,
74+
version = start_date - 1 + c(5, 5, 4, 4),
75+
value = c(1, 2, 3, 4)
76+
) %>%
77+
as_epi_archive() %>%
78+
epi_slide_opt(value, frollmean, .window_size = 2L) %>%
79+
expect_equal(
80+
tibble(
81+
geo_value = 1,
82+
time_value = start_date - 1 + c(1, 2, 3, 3, 4),
83+
version = start_date - 1 + c(5, 5, 4, 5, 4),
84+
value = c(1, 2, 3, 3, 4),
85+
value_2dav = c(NA, 1.5, NA, 2.5, 3.5)
86+
) %>%
87+
as_epi_archive()
88+
)
7289
})
7390

74-
# TODO tests on example data sets
91+
test_that("epi_slide_opt.epi_archive is not confused by unique(DT$time_value) unsorted", {
92+
93+
start_date <- as.Date("2020-01-01")
94+
tibble(
95+
geo_value = c(1, 1, 2, 2),
96+
time_value = start_date - 1 + c(2, 3, 1, 2),
97+
version = start_date - 1 + c(1, 2, 2, 2),
98+
value = c(1, 2, 3, 4)
99+
) %>%
100+
as_epi_archive() %>%
101+
epi_slide_opt(value, frollmean, .window_size = 2L) %>%
102+
expect_equal(
103+
tibble(
104+
geo_value = c(1, 1, 2, 2),
105+
time_value = start_date - 1 + c(2, 3, 1, 2),
106+
version = start_date - 1 + c(1, 2, 2, 2),
107+
value = c(1, 2, 3, 4),
108+
value_2dav = c(NA, 1.5, NA, 3.5)
109+
) %>%
110+
as_epi_archive()
111+
)
112+
113+
})
114+
115+
test_that("epi_slide_opt.epi_archive is equivalent to epix_slide reconversion on example data", {
116+
117+
case_death_rate_archive %>%
118+
epi_slide_opt(case_rate, frollmean, .window_size = 7
119+
# , algo = "exact"
120+
) %>%
121+
.$DT %>%
122+
as.data.frame() %>%
123+
as_tibble() %>%
124+
filter(!approx_equal(case_rate_7dav, case_rate_7d_av, 1e-6, TRUE)) %>%
125+
dplyr::transmute(version, geo_value, time_value, case_rate_7dav, case_rate_7d_av,
126+
abs_diff = abs(case_rate_7dav - case_rate_7d_av)) %>%
127+
{}
128+
129+
# TODO finish tests on example data sets
130+
131+
})
132+
133+
134+
# TODO grouped behavior checks

0 commit comments

Comments
 (0)