@@ -35,20 +35,24 @@ rm(y)
3535
3636xx <- x %> % filter(time_value > " 2021-12-01" )
3737
38+ slm_fit <- function (recipe , data = x ) {
39+ workflow() %> %
40+ add_recipe(recipe ) %> %
41+ add_model(linear_reg()) %> %
42+ fit(data = data )
43+ }
44+
3845# Tests
3946test_that(" Check that epi_ahead shifts properly" , {
40- r <- epi_recipe(x ) %> %
47+ r1 <- epi_recipe(x ) %> %
4148 step_epi_ahead(death_rate , ahead = 7 ) %> %
4249 step_epi_lag(death_rate , lag = - 7 ) %> %
4350 step_naomit(all_predictors()) %> %
4451 step_naomit(all_outcomes(), skip = TRUE )
4552
46- slm_fit <- workflow() %> %
47- add_recipe(r ) %> %
48- add_model(linear_reg()) %> %
49- fit(data = x )
53+ slm_fit1 <- slm_fit(r1 )
5054
51- slope_ahead <- slm_fit $ fit $ fit $ fit $ coefficients [[2 ]]
55+ slope_ahead <- slm_fit1 $ fit $ fit $ fit $ coefficients [[2 ]]
5256 expect_equal(slope_ahead ,1 )
5357})
5458
@@ -59,11 +63,27 @@ test_that("Check that epi_lag shifts properly", {
5963 step_naomit(all_predictors()) %> %
6064 step_naomit(all_outcomes(), skip = TRUE )
6165
62- slm_fit2 <- workflow() %> %
63- add_recipe(r2 ) %> %
64- add_model(linear_reg()) %> %
65- fit(data = x )
66+ slm_fit2 <- slm_fit(r2 )
6667
6768 slope_lag <- slm_fit2 $ fit $ fit $ fit $ coefficients [[2 ]]
6869 expect_equal(slope_lag ,1 )
6970})
71+
72+ test_that(" Check for non-integer values" , {
73+ r3 <- epi_recipe(x ) %> %
74+ step_epi_ahead(death_rate , ahead = 3.6 ) %> %
75+ step_epi_lag(death_rate , lag = 1.9 )
76+ expect_error(
77+ slm_fit(r3 )
78+ )
79+ })
80+
81+ test_that(" Check for duplicate values" , {
82+ r4 <- epi_recipe(x ) %> %
83+ step_epi_ahead(death_rate , ahead = 7 ) %> %
84+ step_epi_lag(death_rate , lag = 7 ) %> %
85+ step_epi_lag(death_rate , lag = 7 )
86+ expect_error(
87+ slm_fit(r4 )
88+ )
89+ })
0 commit comments