@@ -9,6 +9,8 @@ x <- list(cbind(a = 1:3, b = rnorm(3)), cbind(a = 1:3, b = rnorm(3)))
99
1010# nuts_params and log_posterior methods -----------------------------------
1111test_that(" nuts_params.list throws errors" , {
12+ expect_error(nuts_params.list(list ()), " non-empty list" )
13+
1214 x [[3 ]] <- c(a = 1 : 3 , b = rnorm(3 ))
1315 expect_error(nuts_params.list(x ), " list elements should be matrices" )
1416
@@ -17,6 +19,20 @@ test_that("nuts_params.list throws errors", {
1719
1820 x [[3 ]] <- cbind(a = 1 : 4 , b = rnorm(4 ))
1921 expect_error(nuts_params.list(x ), " same dimensions" )
22+
23+ zero_row <- list (cbind(a = numeric (0 ), b = numeric (0 )))
24+ expect_error(nuts_params.list(zero_row ), " at least one row" )
25+
26+ zero_row_nonfirst <- list (cbind(a = 1 : 3 , b = rnorm(3 )), cbind(a = numeric (0 ), b = numeric (0 )))
27+ expect_error(nuts_params.list(zero_row_nonfirst ), " at least one row" )
28+ })
29+
30+ test_that(" nuts_params.list works with single-chain list" , {
31+ single <- list (cbind(a = 1 : 3 , b = rnorm(3 )))
32+ np <- nuts_params.list(single )
33+ expect_identical(colnames(np ), c(" Chain" , " Iteration" , " Parameter" , " Value" ))
34+ expect_true(all(np $ Chain == 1L ))
35+ expect_equal(nrow(np ), 6L )
2036})
2137
2238test_that(" nuts_params.list parameter selection ok" , {
0 commit comments