Skip to content
Open
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# bayesplot (development version)

* Added direct test coverage for exported `_data()` functions: `ppc_data()`, `ppd_data()`, `ppc_ribbon_data()`, and `ppd_ribbon_data()`.
* Eliminate redundant data processing in `mcmc_areas_data()` by reusing the prepared MCMC array for both interval and density computation.
* Validate equal chain lengths in `validate_df_with_chain()`, reject missing
chain labels, and renumber data-frame chain labels internally when converting
Expand Down
51 changes: 51 additions & 0 deletions tests/testthat/test-ppc-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,54 @@ test_that("ppc_pit_ecdf, ppc_pit_ecdf_grouped renders correctly", {
vdiffr::expect_doppelganger("ppc_pit_ecdf (diff)", p_diff)
vdiffr::expect_doppelganger("ppc_pit_ecdf_grouped (diff)", g_diff)
})


# ppc_data / ppd_data tests -----------------------------------------------

test_that("ppc_data returns correct structure", {
d <- ppc_data(y, yrep)
expect_s3_class(d, "data.frame")
expect_true(all(c("y_id", "rep_id", "rep_label", "is_y", "value") %in% names(d)))
})

test_that("ppc_data includes y and yrep rows", {
d <- ppc_data(y, yrep)
y_rows <- d[d$is_y, ]
yrep_rows <- d[!d$is_y, ]
expect_equal(nrow(y_rows), length(y))
expect_equal(nrow(yrep_rows), length(y) * nrow(yrep))
expect_equal(y_rows$value, y)
})

test_that("ppc_data with group adds group column", {
d <- ppc_data(y, yrep, group = group)
expect_true("group" %in% names(d))
expect_equal(nlevels(factor(d$group)), nlevels(group))
})

test_that("ppc_data works with single replicate", {
d <- ppc_data(y, yrep[1, , drop = FALSE])
yrep_rows <- d[!d$is_y, ]
expect_equal(nrow(yrep_rows), length(y))
})

test_that("ppd_data returns correct structure", {
d <- ppd_data(yrep)
expect_s3_class(d, "data.frame")
expect_true(all(c("y_id", "rep_id", "rep_label", "value") %in% names(d)))
})

test_that("ppd_data returns correct number of rows", {
d <- ppd_data(yrep)
expect_equal(nrow(d), nrow(yrep) * ncol(yrep))
})

test_that("ppd_data with group adds group column", {
d <- ppd_data(yrep, group = group)
expect_true("group" %in% names(d))
})

test_that("ppd_data works with single replicate", {
d <- ppd_data(yrep[1, , drop = FALSE])
expect_equal(nrow(d), ncol(yrep))
})
20 changes: 20 additions & 0 deletions tests/testthat/test-ppc-intervals.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,23 @@ test_that("ppc_ribbon_grouped renders correctly", {
group = vdiff_group)
vdiffr::expect_doppelganger("ppd_ribbon_grouped (x values)", p_x)
})


# ppc_ribbon_data / ppd_ribbon_data alias tests ----------------------------

test_that("ppc_ribbon_data is identical to ppc_intervals_data", {
expect_identical(ppc_ribbon_data, ppc_intervals_data)
y_test <- rnorm(20)
yrep_test <- matrix(rnorm(200), ncol = 20)
d1 <- ppc_intervals_data(y_test, yrep_test, prob = 0.5, prob_outer = 0.9)
d2 <- ppc_ribbon_data(y_test, yrep_test, prob = 0.5, prob_outer = 0.9)
expect_identical(d1, d2)
})

test_that("ppd_ribbon_data is identical to ppd_intervals_data", {
expect_identical(ppd_ribbon_data, ppd_intervals_data)
yrep_test <- matrix(rnorm(200), ncol = 20)
d1 <- ppd_intervals_data(yrep_test, prob = 0.5, prob_outer = 0.9)
d2 <- ppd_ribbon_data(yrep_test, prob = 0.5, prob_outer = 0.9)
expect_identical(d1, d2)
})
Loading