1+ skip_if_not_installed(" rstantools" )
12source(test_path(" data-for-ppc-tests.R" ))
23
34test_that(" ppc_error_hist and ppc_error_scatter return ggplot object" , {
4- skip_if_not_installed(" rstantools" )
55 expect_gg(ppc_error_hist(y , yrep [1 : 5 , ], binwidth = 0.1 ))
66 expect_gg(ppc_error_scatter(y , yrep [1 : 5 , ]))
77
@@ -13,14 +13,12 @@ test_that("ppc_error_hist and ppc_error_scatter return ggplot object", {
1313})
1414
1515test_that(" ppc_error_hist_grouped returns ggplot object" , {
16- skip_if_not_installed(" rstantools" )
1716 expect_gg(ppc_error_hist_grouped(y , yrep [1 : 5 , ], group , binwidth = 0.1 ))
1817 expect_gg(ppc_error_hist_grouped(y , yrep [1 ,, drop = FALSE ], group ,
1918 freq = FALSE , binwidth = 1 ))
2019})
2120
2221test_that(" ppc_error_scatter_avg returns ggplot2 object" , {
23- skip_if_not_installed(" rstantools" )
2422 expect_gg(ppc_error_scatter_avg(y , yrep ))
2523 expect_gg(ppc_error_scatter_avg(y , yrep [1 : 5 , ]))
2624
@@ -30,7 +28,6 @@ test_that("ppc_error_scatter_avg returns ggplot2 object", {
3028})
3129
3230test_that(" ppc_error_scatter_avg same as ppc_error_scatter if nrow(yrep) = 1" , {
33- skip_if_not_installed(" rstantools" )
3431 p1 <- ppc_error_scatter_avg(y2 , yrep2 )
3532 p2 <- ppc_error_scatter(y2 , yrep2 )
3633 d1 <- p1 $ data
@@ -42,8 +39,6 @@ test_that("ppc_error_scatter_avg same as ppc_error_scatter if nrow(yrep) = 1", {
4239})
4340
4441test_that(" ppc_error_scatter_avg_vs_x returns ggplot2 object" , {
45- skip_if_not_installed(" rstantools" )
46-
4742 # expect warning
4843 expect_warning(expect_gg(ppc_error_scatter_avg_vs_x(y , yrep , x = rnorm(length(y )))),
4944 " 'ppc_error_scatter_avg_vs_x' is deprecated." )
@@ -52,7 +47,6 @@ test_that("ppc_error_scatter_avg_vs_x returns ggplot2 object", {
5247})
5348
5449test_that(" ppc_error_binned returns ggplot object" , {
55- skip_if_not_installed(" rstantools" )
5650 load(test_path(" data-for-binomial.rda" ))
5751 expect_gg(ppc_error_binned(y , Ey ))
5852 expect_gg(ppc_error_binned(y [1 : 5 ], Ey [, 1 : 5 ]))
@@ -73,6 +67,24 @@ test_that("bin_errors works for edge cases", {
7367 expect_equal(ans , val )
7468})
7569
70+ # ppc_error_data tests -----------------------------------------------------
71+
72+ test_that(" ppc_error_data returns exact structure and computed errors" , {
73+ d <- ppc_error_data(y , yrep )
74+ expect_named(d , c(" y_id" , " y_name" , " y_obs" , " rep_id" , " rep_label" , " value" ))
75+ third_rep <- d [d $ rep_id == 3 , ]
76+ expected_errors <- y - yrep [3 , ]
77+ expect_equal(third_rep $ value , expected_errors )
78+ expect_equal(third_rep $ y_obs , y )
79+ })
80+
81+ test_that(" ppc_error_data with group returns exact structure" , {
82+ d <- ppc_error_data(y , yrep , group = group )
83+ expect_named(d , c(" group" , " y_id" , " y_name" , " y_obs" , " rep_id" , " rep_label" , " value" ))
84+ expect_identical(levels(d $ group ), levels(group ))
85+ expect_equal(d $ group [d $ rep_id == 1 ], group )
86+ })
87+
7688
7789# Visual tests -----------------------------------------------------------------
7890
0 commit comments