Skip to content

Commit c0b5a3f

Browse files
committed
Update test-helpers-ppc.R
1 parent cbde4f0 commit c0b5a3f

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

tests/testthat/test-helpers-ppc.R

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
library(posterior)
21
source(test_path("data-for-ppc-tests.R"))
32
source(test_path("data-for-mcmc-tests.R"))
43

@@ -116,51 +115,52 @@ test_that("get_interpolation_values catches impossible values", {
116115

117116
# validate_predictions with posterior::draws objects ----------------------
118117
test_that("validate_predictions accepts draws_matrix", {
119-
dm <- posterior::as_draws_matrix(yrep)
120-
result <- validate_predictions(dm, ncol(yrep))
118+
result <- validate_predictions(posterior::as_draws_matrix(yrep), ncol(yrep))
121119
expect_true(is.matrix(result))
122120
expect_equal(dim(result), dim(yrep))
123121
expect_true(is.numeric(result))
124122
})
125123

126124
test_that("validate_predictions accepts draws_array", {
127-
da <- posterior::as_draws_array(yrep)
128-
result <- validate_predictions(da)
125+
result <- validate_predictions(posterior::as_draws_array(yrep))
129126
expect_true(is.matrix(result))
130-
expect_true(is.numeric(result))
127+
expect_equal(dim(result), dim(yrep))
131128
})
132129

133130
test_that("validate_predictions accepts draws_df", {
134-
ddf <- posterior::as_draws_df(yrep)
135-
result <- validate_predictions(ddf)
131+
result <- validate_predictions(posterior::as_draws_df(yrep))
136132
expect_true(is.matrix(result))
137-
expect_true(is.numeric(result))
133+
expect_equal(dim(result), dim(yrep))
138134
})
139135

140-
test_that("validate_predictions accepts draws_rvars", {
141-
dr <- posterior::as_draws_rvars(yrep)
142-
result <- validate_predictions(dr)
136+
test_that("validate_predictions accepts draws_list", {
137+
result <- validate_predictions(posterior::as_draws_list(yrep))
143138
expect_true(is.matrix(result))
144-
expect_true(is.numeric(result))
139+
expect_equal(dim(result), dim(yrep))
145140
})
146141

147-
test_that("ppc_dens_overlay works with draws_matrix input", {
148-
dm <- posterior::as_draws_matrix(yrep)
149-
p <- ppc_dens_overlay(y, dm)
150-
expect_s3_class(p, "ggplot")
142+
test_that("validate_predictions accepts draws_rvars", {
143+
result <- validate_predictions(posterior::as_draws_rvars(yrep))
144+
expect_true(is.matrix(result))
145+
expect_equal(dim(result), dim(yrep))
151146
})
152147

153-
test_that("ppc_hist works with draws_matrix input", {
154-
dm <- posterior::as_draws_matrix(yrep)
155-
p <- ppc_hist(y, dm[1:8, ])
156-
expect_s3_class(p, "ggplot")
148+
test_that("posterior::draws input results in identical ggplot data", {
149+
p0 <- ggplot2::ggplot_build(ppc_dens_overlay(y, yrep))
150+
p1 <- ggplot2::ggplot_build(ppc_dens_overlay(y, posterior::as_draws_matrix(yrep)))
151+
p2 <- ggplot2::ggplot_build(ppc_dens_overlay(y, posterior::as_draws_array(yrep)))
152+
p3 <- ggplot2::ggplot_build(ppc_dens_overlay(y, posterior::as_draws_df(yrep)))
153+
p4 <- ggplot2::ggplot_build(ppc_dens_overlay(y, posterior::as_draws_list(yrep)))
154+
p5 <- ggplot2::ggplot_build(ppc_dens_overlay(y, posterior::as_draws_rvars(yrep)))
155+
156+
expect_identical(p1@data, p0@data)
157+
expect_identical(p2@data, p0@data)
158+
expect_identical(p3@data, p0@data)
159+
expect_identical(p4@data, p0@data)
160+
expect_identical(p5@data, p0@data)
157161
})
158162

159-
test_that("ppc_stat works with draws_matrix input", {
160-
dm <- posterior::as_draws_matrix(yrep)
161-
p <- ppc_stat(y, dm)
162-
expect_s3_class(p, "ggplot")
163-
})
163+
164164

165165
# ecdf_intervals ---------------------------------------------------------
166166
test_that("ecdf_intervals returns right dimensions and values", {

0 commit comments

Comments
 (0)