Skip to content

Commit 54dcd14

Browse files
CopilotVisruthSK
andcommitted
Add tests for invalid bounds in density plotting functions (#406)
* Initial plan * Add tests for invalid bounds in plotting functions Co-authored-by: VisruthSK <67435125+VisruthSK@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: VisruthSK <67435125+VisruthSK@users.noreply.github.com>
1 parent 3647792 commit 54dcd14

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

tests/testthat/test-mcmc-distributions.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ test_that("mcmc density plots accept bounds", {
6161
suppressWarnings(expect_gg(mcmc_dens_chains(arr, pars = "beta[1]", bounds = c(0, Inf))))
6262
})
6363

64+
test_that("mcmc density plots reject invalid bounds", {
65+
# non-numeric bounds
66+
expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c("a", "b")),
67+
"`bounds` must be a numeric vector of length 2")
68+
69+
# bounds with length != 2
70+
expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c(0, 1, 2)),
71+
"`bounds` must be a numeric vector of length 2")
72+
expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = 1),
73+
"`bounds` must be a numeric vector of length 2")
74+
75+
# bounds with NA values
76+
expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c(0, NA)),
77+
"`bounds` must be a numeric vector of length 2")
78+
expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c(NA, 1)),
79+
"`bounds` must be a numeric vector of length 2")
80+
81+
# bounds where bounds[1] >= bounds[2]
82+
expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c(1, 0)),
83+
"`bounds` must satisfy bounds\\[1\\] < bounds\\[2\\]")
84+
expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c(1, 1)),
85+
"`bounds` must satisfy bounds\\[1\\] < bounds\\[2\\]")
86+
})
87+
6488
test_that("mcmc_dens_chains returns a ggplot object", {
6589
p <- mcmc_dens_chains(arr, pars = "beta[1]", regex_pars = "x\\:",
6690
color_chains = FALSE)

tests/testthat/test-ppc-distributions.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ test_that("density PPC/PPD plots accept bounds", {
1717
suppressWarnings(expect_gg(ppd_dens_overlay(yrep, bounds = c(0, Inf))))
1818
})
1919

20+
test_that("density PPC/PPD plots reject invalid bounds", {
21+
# non-numeric bounds
22+
expect_error(ppc_dens_overlay(y, yrep, bounds = c("a", "b")),
23+
"`bounds` must be a numeric vector of length 2")
24+
25+
# bounds with length != 2
26+
expect_error(ppc_dens_overlay(y, yrep, bounds = c(0, 1, 2)),
27+
"`bounds` must be a numeric vector of length 2")
28+
expect_error(ppc_dens_overlay(y, yrep, bounds = 1),
29+
"`bounds` must be a numeric vector of length 2")
30+
31+
# bounds with NA values
32+
expect_error(ppc_dens_overlay(y, yrep, bounds = c(0, NA)),
33+
"`bounds` must be a numeric vector of length 2")
34+
expect_error(ppc_dens_overlay(y, yrep, bounds = c(NA, 1)),
35+
"`bounds` must be a numeric vector of length 2")
36+
37+
# bounds where bounds[1] >= bounds[2]
38+
expect_error(ppc_dens_overlay(y, yrep, bounds = c(1, 0)),
39+
"`bounds` must satisfy bounds\\[1\\] < bounds\\[2\\]")
40+
expect_error(ppc_dens_overlay(y, yrep, bounds = c(1, 1)),
41+
"`bounds` must satisfy bounds\\[1\\] < bounds\\[2\\]")
42+
})
43+
2044
test_that("ppc_ecdf_overlay returns a ggplot object", {
2145
expect_gg(ppc_ecdf_overlay(y, yrep, size = 0.5, alpha = 0.2))
2246
expect_gg(ppc_ecdf_overlay(y2, yrep2))

0 commit comments

Comments
 (0)