Skip to content

Commit d44b41f

Browse files
committed
test errors from as_slide_computation
1 parent e709ea2 commit d44b41f

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

man/as_slide_computation.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epi_slide.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epix_slide.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-utils.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,24 @@ test_that("computation formula-derived functions take all argument types", {
196196
expect_identical(as_slide_computation(~ . + .ref_time_value)(1, 2, 3), 4)
197197
expect_identical(as_slide_computation(~ .group_key)(1, 2, 3), 2)
198198
})
199+
200+
test_that("as_slide_computation passes functions unaltered", {
201+
f <- function(a, b, c) {a * b * c + 5}
202+
expect_identical(as_slide_computation(f), f)
203+
})
204+
205+
test_that("as_slide_computation raises errors as expected", {
206+
# Formulas must be one-sided
207+
expect_error(as_slide_computation(y ~ ..1),
208+
class="epiprocess__as_slide_computation__formula_is_twosided")
209+
210+
# `f_env` must be an environment
211+
formula_without_env <- stats::as.formula(~ ..1)
212+
rlang::f_env(formula_without_env) <- 5
213+
expect_error(as_slide_computation(formula_without_env),
214+
class="epiprocess__as_slide_computation__formula_has_no_env")
215+
216+
# `f` must be a function, formula, or string
217+
expect_error(as_slide_computation(5),
218+
class="epiprocess__as_slide_computation__cant_convert_catchall")
219+
})

0 commit comments

Comments
 (0)