Skip to content

Commit 4458903

Browse files
committed
Add test coverage for ppc_data, ppd_data, ppc_ribbon_data, ppd_ribbon_data
1 parent b19e3cd commit 4458903

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

tests/testthat/test-ppc-distributions.R

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,54 @@ test_that("ppc_pit_ecdf, ppc_pit_ecdf_grouped renders correctly", {
422422
vdiffr::expect_doppelganger("ppc_pit_ecdf (diff)", p_diff)
423423
vdiffr::expect_doppelganger("ppc_pit_ecdf_grouped (diff)", g_diff)
424424
})
425+
426+
427+
# ppc_data / ppd_data tests -----------------------------------------------
428+
429+
test_that("ppc_data returns correct structure", {
430+
d <- ppc_data(y, yrep)
431+
expect_s3_class(d, "data.frame")
432+
expect_true(all(c("y_id", "rep_id", "rep_label", "is_y", "value") %in% names(d)))
433+
})
434+
435+
test_that("ppc_data includes y and yrep rows", {
436+
d <- ppc_data(y, yrep)
437+
y_rows <- d[d$is_y, ]
438+
yrep_rows <- d[!d$is_y, ]
439+
expect_equal(nrow(y_rows), length(y))
440+
expect_equal(nrow(yrep_rows), length(y) * nrow(yrep))
441+
expect_equal(y_rows$value, y)
442+
})
443+
444+
test_that("ppc_data with group adds group column", {
445+
d <- ppc_data(y, yrep, group = group)
446+
expect_true("group" %in% names(d))
447+
expect_equal(nlevels(factor(d$group)), nlevels(group))
448+
})
449+
450+
test_that("ppc_data works with single replicate", {
451+
d <- ppc_data(y, yrep[1, , drop = FALSE])
452+
yrep_rows <- d[!d$is_y, ]
453+
expect_equal(nrow(yrep_rows), length(y))
454+
})
455+
456+
test_that("ppd_data returns correct structure", {
457+
d <- ppd_data(yrep)
458+
expect_s3_class(d, "data.frame")
459+
expect_true(all(c("y_id", "rep_id", "rep_label", "value") %in% names(d)))
460+
})
461+
462+
test_that("ppd_data returns correct number of rows", {
463+
d <- ppd_data(yrep)
464+
expect_equal(nrow(d), nrow(yrep) * ncol(yrep))
465+
})
466+
467+
test_that("ppd_data with group adds group column", {
468+
d <- ppd_data(yrep, group = group)
469+
expect_true("group" %in% names(d))
470+
})
471+
472+
test_that("ppd_data works with single replicate", {
473+
d <- ppd_data(yrep[1, , drop = FALSE])
474+
expect_equal(nrow(d), ncol(yrep))
475+
})

tests/testthat/test-ppc-intervals.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,23 @@ test_that("ppc_ribbon_grouped renders correctly", {
224224
group = vdiff_group)
225225
vdiffr::expect_doppelganger("ppd_ribbon_grouped (x values)", p_x)
226226
})
227+
228+
229+
# ppc_ribbon_data / ppd_ribbon_data alias tests ----------------------------
230+
231+
test_that("ppc_ribbon_data is identical to ppc_intervals_data", {
232+
expect_identical(ppc_ribbon_data, ppc_intervals_data)
233+
y_test <- rnorm(20)
234+
yrep_test <- matrix(rnorm(200), ncol = 20)
235+
d1 <- ppc_intervals_data(y_test, yrep_test, prob = 0.5, prob_outer = 0.9)
236+
d2 <- ppc_ribbon_data(y_test, yrep_test, prob = 0.5, prob_outer = 0.9)
237+
expect_identical(d1, d2)
238+
})
239+
240+
test_that("ppd_ribbon_data is identical to ppd_intervals_data", {
241+
expect_identical(ppd_ribbon_data, ppd_intervals_data)
242+
yrep_test <- matrix(rnorm(200), ncol = 20)
243+
d1 <- ppd_intervals_data(yrep_test, prob = 0.5, prob_outer = 0.9)
244+
d2 <- ppd_ribbon_data(yrep_test, prob = 0.5, prob_outer = 0.9)
245+
expect_identical(d1, d2)
246+
})

0 commit comments

Comments
 (0)