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
24 changes: 24 additions & 0 deletions tests/testthat/test-mcmc-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test-ppc-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading