| 1 |
describe("with_rng_version", { |
| 2 |
it("changes the RNG", { |
| 3 |
cur <- RNGkind() |
| 4 |
old <-with_rng_version("1.6.0", RNGkind()) |
| 5 |
expect_equal(old[1], "Marsaglia-Multicarry") |
| 6 |
expect_true(old[1] != cur[1]) |
| 7 |
}) |
| 8 |
|
| 9 |
it("restores the RNG", { |
| 10 |
cur <- RNGkind() |
| 11 |
with_rng_version("1.6.0", RNGkind()) |
| 12 |
expect_identical(cur, RNGkind()) |
| 13 |
}) |
| 14 |
}) |
| 15 |
|
| 16 |
describe("local_rng_version", { |
| 17 |
it("changes the RNG", { |
| 18 |
fun <- function() { |
| 19 |
local_rng_version("1.6.0") |
| 20 |
RNGkind() |
| 21 |
} |
| 22 |
expect_identical( |
| 23 |
with_rng_version("1.6.0", RNGkind()), |
| 24 |
fun() |
| 25 |
) |
| 26 |
}) |
| 27 |
|
| 28 |
it("restores the RNG", { |
| 29 |
cur <- RNGkind() |
| 30 |
fun <- function() { |
| 31 |
local_rng_version("1.6.0") |
| 32 |
"foobar" |
| 33 |
} |
| 34 |
expect_identical( |
| 35 |
cur, |
| 36 |
RNGkind() |
| 37 |
) |
| 38 |
}) |
| 39 |
}) |