Skip to content

Commit d15d028

Browse files
authored
Merge pull request #493 from utkarshpawade/fix/add-tidy-params-unit-tests
Add unit tests for tidy parameter selection helpers
2 parents 104facb + 1e64594 commit d15d028

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# bayesplot (development version)
22

3+
* Added unit tests for previously untested edge cases in `param_range()`, `param_glue()`, and `tidyselect_parameters()` (no-match, partial-match, and negation behavior).
34
* Bumped minimum version for `rstantools` from `>= 1.5.0` to `>= 2.0.0` .
45
* Use `rlang::warn()` and `rlang::inform()` for selected PPC user messages instead of base `warning()` and `message()`.
56
* Standardize input validation errors in `ppc_km_overlay()` and interpolation helpers to use `rlang::abort()` for consistent error handling.

tests/testthat/test-tidy-params.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)