|
| 1 | +source(test_path("data-for-mcmc-tests.R")) |
| 2 | + |
| 3 | +# param_range -------------------------------------------------------------- |
| 4 | + |
| 5 | +test_that("param_range returns empty integer when no matches", { |
| 6 | + all_pars <- c("alpha", "gamma[1]", "gamma[2]") |
| 7 | + result <- param_range("beta", 1:3, vars = all_pars) |
| 8 | + expect_identical(result, integer(0)) |
| 9 | +}) |
| 10 | + |
| 11 | +test_that("param_range drops non-matching indices silently", { |
| 12 | + all_pars <- c("alpha", "beta[1]", "beta[3]") |
| 13 | + # beta[2] does not exist, should be silently dropped |
| 14 | + result <- param_range("beta", 1:3, vars = all_pars) |
| 15 | + expect_equal(result, c(2L, 3L)) |
| 16 | +}) |
| 17 | + |
| 18 | +# param_glue --------------------------------------------------------------- |
| 19 | + |
| 20 | +test_that("param_glue returns empty integer when no matches", { |
| 21 | + all_pars <- c("alpha", "sigma") |
| 22 | + result <- param_glue("beta[{i}]", i = 1:3, vars = all_pars) |
| 23 | + expect_identical(result, integer(0)) |
| 24 | +}) |
| 25 | + |
| 26 | +test_that("param_glue drops non-matching names silently", { |
| 27 | + all_pars <- c("b[X:1]", "b[Y:2]", "sigma") |
| 28 | + # b[X:2] and b[Y:1] don't exist |
| 29 | + result <- param_glue("b[{var}:{lev}]", var = c("X", "Y"), lev = c(1, 2), |
| 30 | + vars = all_pars) |
| 31 | + expect_equal(result, c(1L, 2L)) |
| 32 | +}) |
| 33 | + |
| 34 | +# tidyselect_parameters ---------------------------------------------------- |
| 35 | + |
| 36 | +test_that("tidyselect_parameters works with negation", { |
| 37 | + all_pars <- c("alpha", "beta[1]", "beta[2]", "sigma") |
| 38 | + selected <- tidyselect_parameters(all_pars, vars(-alpha)) |
| 39 | + expect_equal(selected, c("beta[1]", "beta[2]", "sigma")) |
| 40 | +}) |
0 commit comments