Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# bayesplot (development version)

* Added unit tests for previously untested edge cases in `param_range()`, `param_glue()`, and `tidyselect_parameters()` (no-match, partial-match, and negation behavior).
* Bumped minimum version for `rstantools` from `>= 1.5.0` to `>= 2.0.0` .
* Use `rlang::warn()` and `rlang::inform()` for selected PPC user messages instead of base `warning()` and `message()`.
* Standardize input validation errors in `ppc_km_overlay()` and interpolation helpers to use `rlang::abort()` for consistent error handling.
Expand Down
40 changes: 40 additions & 0 deletions tests/testthat/test-tidy-params.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
source(test_path("data-for-mcmc-tests.R"))

# param_range --------------------------------------------------------------

test_that("param_range returns empty integer when no matches", {
all_pars <- c("alpha", "gamma[1]", "gamma[2]")
result <- param_range("beta", 1:3, vars = all_pars)
expect_identical(result, integer(0))
})

test_that("param_range drops non-matching indices silently", {
all_pars <- c("alpha", "beta[1]", "beta[3]")
# beta[2] does not exist, should be silently dropped
result <- param_range("beta", 1:3, vars = all_pars)
expect_equal(result, c(2L, 3L))
})

# param_glue ---------------------------------------------------------------

test_that("param_glue returns empty integer when no matches", {
all_pars <- c("alpha", "sigma")
result <- param_glue("beta[{i}]", i = 1:3, vars = all_pars)
expect_identical(result, integer(0))
})

test_that("param_glue drops non-matching names silently", {
all_pars <- c("b[X:1]", "b[Y:2]", "sigma")
# b[X:2] and b[Y:1] don't exist
result <- param_glue("b[{var}:{lev}]", var = c("X", "Y"), lev = c(1, 2),
vars = all_pars)
expect_equal(result, c(1L, 2L))
})

# tidyselect_parameters ----------------------------------------------------

test_that("tidyselect_parameters works with negation", {
all_pars <- c("alpha", "beta[1]", "beta[2]", "sigma")
selected <- tidyselect_parameters(all_pars, vars(-alpha))
expect_equal(selected, c("beta[1]", "beta[2]", "sigma"))
})
Loading