From c3ba7ae1cfaacb9a8bd2b3112745181d3ffbb28b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Dec 2025 01:51:01 +0000 Subject: [PATCH 1/2] Initial plan From ed070fdea8d03cb3838b2c0e4eb5942ef613aa0e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Dec 2025 02:25:33 +0000 Subject: [PATCH 2/2] Add tests for invalid bounds in plotting functions Co-authored-by: VisruthSK <67435125+VisruthSK@users.noreply.github.com> --- tests/testthat/test-mcmc-distributions.R | 24 ++++++++++++++++++++++++ tests/testthat/test-ppc-distributions.R | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/tests/testthat/test-mcmc-distributions.R b/tests/testthat/test-mcmc-distributions.R index 72c32705..109749c6 100644 --- a/tests/testthat/test-mcmc-distributions.R +++ b/tests/testthat/test-mcmc-distributions.R @@ -61,6 +61,30 @@ test_that("mcmc density plots accept bounds", { suppressWarnings(expect_gg(mcmc_dens_chains(arr, pars = "beta[1]", bounds = c(0, Inf)))) }) +test_that("mcmc density plots reject invalid bounds", { + # non-numeric bounds + expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c("a", "b")), + "`bounds` must be a numeric vector of length 2") + + # bounds with length != 2 + expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c(0, 1, 2)), + "`bounds` must be a numeric vector of length 2") + expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = 1), + "`bounds` must be a numeric vector of length 2") + + # bounds with NA values + expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c(0, NA)), + "`bounds` must be a numeric vector of length 2") + expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c(NA, 1)), + "`bounds` must be a numeric vector of length 2") + + # bounds where bounds[1] >= bounds[2] + expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c(1, 0)), + "`bounds` must satisfy bounds\\[1\\] < bounds\\[2\\]") + expect_error(mcmc_dens(arr, pars = "beta[1]", bounds = c(1, 1)), + "`bounds` must satisfy bounds\\[1\\] < bounds\\[2\\]") +}) + test_that("mcmc_dens_chains returns a ggplot object", { p <- mcmc_dens_chains(arr, pars = "beta[1]", regex_pars = "x\\:", color_chains = FALSE) diff --git a/tests/testthat/test-ppc-distributions.R b/tests/testthat/test-ppc-distributions.R index 574b4a47..53870bcb 100644 --- a/tests/testthat/test-ppc-distributions.R +++ b/tests/testthat/test-ppc-distributions.R @@ -17,6 +17,30 @@ test_that("density PPC/PPD plots accept bounds", { suppressWarnings(expect_gg(ppd_dens_overlay(yrep, bounds = c(0, Inf)))) }) +test_that("density PPC/PPD plots reject invalid bounds", { + # non-numeric bounds + expect_error(ppc_dens_overlay(y, yrep, bounds = c("a", "b")), + "`bounds` must be a numeric vector of length 2") + + # bounds with length != 2 + expect_error(ppc_dens_overlay(y, yrep, bounds = c(0, 1, 2)), + "`bounds` must be a numeric vector of length 2") + expect_error(ppc_dens_overlay(y, yrep, bounds = 1), + "`bounds` must be a numeric vector of length 2") + + # bounds with NA values + expect_error(ppc_dens_overlay(y, yrep, bounds = c(0, NA)), + "`bounds` must be a numeric vector of length 2") + expect_error(ppc_dens_overlay(y, yrep, bounds = c(NA, 1)), + "`bounds` must be a numeric vector of length 2") + + # bounds where bounds[1] >= bounds[2] + expect_error(ppc_dens_overlay(y, yrep, bounds = c(1, 0)), + "`bounds` must satisfy bounds\\[1\\] < bounds\\[2\\]") + expect_error(ppc_dens_overlay(y, yrep, bounds = c(1, 1)), + "`bounds` must satisfy bounds\\[1\\] < bounds\\[2\\]") +}) + test_that("ppc_ecdf_overlay returns a ggplot object", { expect_gg(ppc_ecdf_overlay(y, yrep, size = 0.5, alpha = 0.2)) expect_gg(ppc_ecdf_overlay(y2, yrep2))