Skip to content

Commit bec78a2

Browse files
committed
remove / revise some silent tests
1 parent dcf778c commit bec78a2

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

tests/testthat/test-population_scaling.R

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@ test_that("Column names can be passed with and without the tidy way", {
55
value = c(1000, 2000, 3000, 4000, 5000, 6000)
66
)
77

8-
newdata <- case_death_rate_subset %>% filter(geo_value %in% c("ak", "al", "ar", "as", "az", "ca"))
8+
pop_data2 <- pop_data %>% dplyr::rename(geo_value = states)
9+
10+
newdata <- case_death_rate_subset %>%
11+
filter(geo_value %in% c("ak", "al", "ar", "as", "az", "ca"))
912

1013
r1 <- epi_recipe(newdata) %>%
11-
step_population_scaling(c("case_rate", "death_rate"),
14+
step_population_scaling(
15+
case_rate, death_rate,
1216
df = pop_data,
13-
df_pop_col = "value", by = c("geo_value" = "states")
17+
df_pop_col = "value",
18+
by = c("geo_value" = "states")
1419
)
1520

1621
r2 <- epi_recipe(newdata) %>%
17-
step_population_scaling(case_rate, death_rate,
18-
df = pop_data,
19-
df_pop_col = "value", by = c("geo_value" = "states")
22+
step_population_scaling(
23+
case_rate, death_rate,
24+
df = pop_data2,
25+
df_pop_col = "value",
26+
by = "geo_value"
2027
)
2128

2229
prep1 <- prep(r1, newdata)
@@ -56,9 +63,9 @@ test_that("Number of columns and column names returned correctly, Upper and lowe
5663
suffix = "_rate"
5764
)
5865

59-
prep <- prep(r, newdata)
66+
p <- prep(r, newdata)
6067

61-
expect_silent(b <- bake(prep, newdata))
68+
b <- bake(p, newdata)
6269
expect_equal(ncol(b), 7L)
6370
expect_true("case_rate" %in% colnames(b))
6471
expect_true("death_rate" %in% colnames(b))
@@ -75,15 +82,15 @@ test_that("Number of columns and column names returned correctly, Upper and lowe
7582
create_new = FALSE
7683
)
7784

78-
expect_warning(prep <- prep(r, newdata))
85+
expect_warning(p <- prep(r, newdata))
7986

80-
expect_warning(b <- bake(prep, newdata))
87+
expect_warning(b <- bake(p, newdata))
8188
expect_equal(ncol(b), 5L)
8289
})
8390

8491
## Postprocessing
8592
test_that("Postprocessing workflow works and values correct", {
86-
jhu <- epiprocess::jhu_csse_daily_subset %>%
93+
jhu <- jhu_csse_daily_subset %>%
8794
dplyr::filter(time_value > "2021-11-01", geo_value %in% c("ca", "ny")) %>%
8895
dplyr::select(geo_value, time_value, cases)
8996

@@ -207,9 +214,17 @@ test_that("test joining by default columns", {
207214
recipes::step_naomit(recipes::all_predictors()) %>%
208215
recipes::step_naomit(recipes::all_outcomes(), skip = TRUE)
209216

210-
expect_silent(prep(r, jhu))
217+
p <- prep(r, jhu)
218+
b <- bake(p, new_data = NULL)
219+
expect_named(
220+
b,
221+
c("geo_value", "time_value", "case_rate", "case_rate_scaled",
222+
paste0("lag_", c(0,7,14), "_case_rate_scaled"),
223+
"ahead_7_case_rate_scaled"
224+
)
225+
)
226+
211227

212-
expect_silent(bake(prep(r, jhu), new_data = NULL))
213228

214229
f <- frosting() %>%
215230
layer_predict() %>%
@@ -221,13 +236,13 @@ test_that("test joining by default columns", {
221236
df_pop_col = "values"
222237
)
223238

224-
expect_silent(
225-
wf <- epi_workflow(r, parsnip::linear_reg()) %>%
226-
fit(jhu) %>%
227-
add_frosting(f)
228-
)
239+
wf <- epi_workflow(r, parsnip::linear_reg()) %>%
240+
fit(jhu) %>%
241+
add_frosting(f)
229242

230-
expect_silent(forecast(wf))
243+
fc <- forecast(wf)
244+
expect_named(fc, c("geo_value", "time_value", ".pred", ".pred_scaled"))
245+
expect_equal(fc$.pred_scaled, fc$.pred * c(1 / 20000, 1 / 30000))
231246
})
232247

233248

0 commit comments

Comments
 (0)