diff --git a/tests/testthat/test-memoise.R b/tests/testthat/test-memoise.R index 4ff7dda..b36032b 100644 --- a/tests/testthat/test-memoise.R +++ b/tests/testthat/test-memoise.R @@ -327,19 +327,28 @@ test_that("omit_args respected", { expect_true(identical(res1, res2)) - # Also works for default args - f <- function(n, x = rnorm(1)) { - rnorm(n) + # Also works for default arguments + a <- 0 + f <- function(x = a) { + a <<- a + 1 + a } - mem_f <- memoise(f) - expect_false(identical(res1, res2)) - res1 <- mem_f(1) - res2 <- mem_f(1) + # everytime `f()` is called its value increases by 1 + expect_equal(f(), 1) + expect_equal(f(), 2) + + # it still increases by one when memoised as the argument `x` changes + a <- 0 + mem_f <- memoise::memoise(f) + expect_equal(mem_f(), 1) + expect_equal(mem_f(), 2) + + # but `x` can be ignored via `omit_args` + a <- 0 mem_f2 <- memoise(f, omit_args = "x") - res1 <- mem_f2(1) - res2 <- mem_f2(1) - expect_true(identical(res1, res2)) + expect_equal(mem_f2(), 1) + expect_equal(mem_f2(), 1) }) context("has_cache")