Skip to content

Commit cfde0c9

Browse files
committed
Merge branch '291-date-period' of https://github.com/cmu-delphi/epipredict into 291-date-period
2 parents 047caa6 + 8feef06 commit cfde0c9

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

tests/testthat/test-layer_add_forecast_date.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,28 @@ test_that("forecast date works for daily", {
8484

8585
wf1 <- add_frosting(wf, f)
8686
p <- predict(wf1, latest)
87+
# both forecast_date and epi_df are dates
8788
expect_identical(p$forecast_date[1], as.Date("2021-12-31"))
8889

89-
latest_bad <- latest %>%
90+
# forecast_date is a date while the epi_df uses years (ints)
91+
latest_yearly <- latest %>%
9092
unclass() %>%
9193
as.data.frame() %>%
9294
mutate(time_value = as.POSIXlt(time_value)$year + 1900L) %>%
9395
as_epi_df()
96+
expect_error(predict(wf1, latest_yearly))
9497

95-
expect_error(predict(wf1, latest_bad))
96-
wf1 <- add_frosting(
98+
# forecast_date is a string
99+
wf2 <- add_frosting(
97100
wf,
98101
adjust_frosting(f, "layer_add_forecast_date", forecast_date = "2022-01-01")
99102
)
100-
expect_silent(predict(wf1, latest))
103+
expect_silent(predict(wf2, latest))
101104

102-
wf1 <- add_frosting(
105+
# forecast_date is a year/int while the epi_df is a date
106+
wf3 <- add_frosting(
103107
wf,
104108
adjust_frosting(f, "layer_add_forecast_date", forecast_date = 2022L)
105109
)
106-
expect_error(predict(wf1, latest)) # wrong time type of forecast_date
110+
expect_error(predict(wf3, latest))
107111
})

tests/testthat/test-layer_add_target_date.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ test_that("Specify own target date", {
8787
expect_named(p2, c("geo_value", "time_value", ".pred", "target_date"))
8888
})
8989

90-
test_that("forecast date works for daily", {
90+
test_that("forecast date works for daily and yearly", {
9191
f <- frosting() %>%
9292
layer_predict() %>%
9393
layer_add_target_date() %>%

0 commit comments

Comments
 (0)