@@ -77,6 +77,27 @@ test_that("ppc_bars_data includes all levels", {
7777 expect_equal(d3 $ h [2 ], 0 , ignore_attr = TRUE )
7878})
7979
80+ test_that(" ppc_bars_data handles single observation and single draw" , {
81+ y1 <- 2L
82+ yrep1 <- matrix (c(1L , 2L , 3L , 2L , 2L ), ncol = 1 )
83+ d <- ppc_bars_data(y1 , yrep1 )
84+ expect_s3_class(d , " data.frame" )
85+ expect_equal(d $ y_obs [d $ x == 2 ], 1 )
86+
87+ # single draw: interval collapses to a point
88+ y_s <- c(1L , 2L , 3L , 2L )
89+ yrep_s <- matrix (c(1L , 2L , 2L , 3L ), nrow = 1 )
90+ d2 <- ppc_bars_data(y_s , yrep_s )
91+ expect_equal(d2 $ l , d2 $ m , ignore_attr = TRUE )
92+ expect_equal(d2 $ m , d2 $ h , ignore_attr = TRUE )
93+ })
94+
95+ test_that(" ppc_bars_data prob = 0 collapses interval to median" , {
96+ d <- ppc_bars_data(y_ord , yrep_ord , prob = 0 )
97+ expect_equal(d $ l , d $ m , ignore_attr = TRUE )
98+ expect_equal(d $ m , d $ h , ignore_attr = TRUE )
99+ })
100+
80101
81102# rootograms -----------------------------------------------------------
82103yrep3 <- matrix (yrep2 , nrow = 5 , ncol = ncol(yrep2 ), byrow = TRUE )
0 commit comments