Skip to content

Commit a6afc1a

Browse files
committed
test mcmc_hex throws same errors as scatter if nparams != 2
1 parent b7bc728 commit a6afc1a

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

tests/testthat/test-mcmc-scatter-and-parcoord.R

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library(bayesplot)
22
suppressPackageStartupMessages(library(rstanarm))
3-
context("MCMC: scatter and parallel coordinates plots")
3+
context("MCMC: scatter, hex, and parallel coordinates plots")
44

55
source(test_path("data-for-mcmc-tests.R"))
66

@@ -15,6 +15,8 @@ divs <- sample(c(0,1), size = 1000, prob = c(0.25, 0.75), replace = TRUE)
1515
np$Value[np$Parameter=="divergent__"] <- divs # fake divergences
1616

1717

18+
19+
# mcmc_scatter/hex --------------------------------------------------------
1820
test_that("mcmc_scatter returns a ggplot object", {
1921
expect_gg(mcmc_scatter(arr, pars = c("beta[1]", "beta[2]")))
2022
expect_gg(mcmc_scatter(arr1chain, regex_pars = "beta", size = 3, alpha = 0.5))
@@ -24,13 +26,8 @@ test_that("mcmc_scatter returns a ggplot object", {
2426
pars = c("sigma", "(Intercept)")))
2527
})
2628

27-
test_that("mcmc_hex returns a ggplot object", {
28-
skip_if_not_installed("hexbin")
29-
expect_gg(mcmc_hex(arr, pars = c("beta[1]", "beta[2]")))
30-
expect_gg(mcmc_hex(arr1chain, regex_pars = "beta", binwidth = c(.5,.5)))
31-
})
32-
33-
test_that("mcmc_scatter throws error if only 1 parameter", {
29+
test_that("mcmc_scatter throws error if number of parameters is not 2", {
30+
expect_error(mcmc_scatter(arr, pars = c("sigma", "beta[1]", "beta[2]")), "exactly 2 parameters")
3431
expect_error(mcmc_scatter(arr, pars = "sigma"), "exactly 2 parameters")
3532
expect_error(mcmc_scatter(arr1), "exactly 2 parameters")
3633
expect_error(mcmc_scatter(mat1), "exactly 2 parameters")
@@ -46,6 +43,21 @@ test_that("mcmc_scatter accepts NUTS info", {
4643
expect_named(g$data, c("x", "y", "Divergent"))
4744
})
4845

46+
test_that("mcmc_hex returns a ggplot object", {
47+
skip_if_not_installed("hexbin")
48+
expect_gg(mcmc_hex(arr, pars = c("beta[1]", "beta[2]")))
49+
expect_gg(mcmc_hex(arr1chain, regex_pars = "beta", binwidth = c(.5,.5)))
50+
})
51+
52+
test_that("mcmc_hex throws error if number of parameters is not 2", {
53+
skip_if_not_installed("hexbin")
54+
expect_error(mcmc_hex(arr, pars = c("sigma", "beta[1]", "beta[2]")), "exactly 2 parameters")
55+
expect_error(mcmc_hex(arr, pars = "sigma"), "exactly 2 parameters")
56+
expect_error(mcmc_hex(arr1), "exactly 2 parameters")
57+
expect_error(mcmc_hex(mat1), "exactly 2 parameters")
58+
})
59+
60+
4961

5062
# mcmc_pairs -------------------------------------------------------------
5163
test_that("mcmc_pairs returns a bayesplot_grid object", {

0 commit comments

Comments
 (0)