Skip to content

Commit 59b04b8

Browse files
authored
Merge pull request #158 from dajmcdon/km-test-methods-epi_archive2
Added epi_archive method tests, excluding for epix_slide
2 parents ba78d43 + ddcfde8 commit 59b04b8

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

tests/testthat/test-methods-epi_archive.R

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,37 @@ test_that("Warning against max_version being same as edf's max version",{
2323
})
2424

2525
test_that("as_of properly grabs the data",{
26-
df_as_of <- ea %>%
27-
epix_as_of(max_version = as.Date("2020-07-01")) %>%
28-
na.omit() %>%
29-
as.data.frame()
30-
31-
df_filter <- ea$DT %>%
32-
filter(version == as.Date("2020-07-01")) %>%
33-
na.omit() %>%
34-
select(-version) %>%
35-
as.data.frame()
26+
d <- as.Date("2020-06-01")
3627

37-
expect_equal(df_as_of[1:4],df_filter)
28+
ea2 = tibble::tribble(
29+
~geo_value, ~time_value, ~version, ~cases,
30+
"ca", "2020-06-01", "2020-06-01", 1,
31+
"ca", "2020-06-01", "2020-06-02", 2,
32+
#
33+
"ca", "2020-06-02", "2020-06-02", 0,
34+
"ca", "2020-06-02", "2020-06-03", 1,
35+
"ca", "2020-06-02", "2020-06-04", 2,
36+
#
37+
"ca", "2020-06-03", "2020-06-03", 1,
38+
#
39+
"ca", "2020-06-04", "2020-06-04", 4,
40+
) %>%
41+
dplyr::mutate(dplyr::across(c(time_value, version), as.Date)) %>%
42+
as_epi_archive()
43+
44+
df_as_of <- ea2 %>%
45+
epix_as_of(max_version = as.Date("2020-06-03")) %>%
46+
as_tibble()
47+
48+
df_expected <- tibble(
49+
geo_value = "ca",
50+
time_value = d + 0:2,
51+
cases = c(2,1,1)
52+
)
53+
54+
expect_identical(df_as_of[[1]],df_expected[[1]])
55+
expect_identical(df_as_of[[2]],df_expected[[2]])
56+
expect_identical(df_as_of[[3]],df_expected[[3]])
3857
})
3958

4059
# epix_merge tests
@@ -50,7 +69,7 @@ test_that("data.table merging is utilized if second argument is a data.table",{
5069

5170
expect_identical(
5271
epix_merge(ea1,dt2),
53-
merge(dt1,dt2)
72+
merge(dt1,dt2,all=TRUE)
5473
)
5574
})
5675

@@ -62,6 +81,6 @@ test_that("data.table merging works as intended",{
6281

6382
expect_identical(
6483
as_epi_archive(ea$DT),
65-
as_epi_archive(merge(dt1,dt2))
84+
as_epi_archive(merge(dt1,dt2,all=TRUE))
6685
)
6786
})

0 commit comments

Comments
 (0)