testthat::test_that("post-processing rejects malformed support", { fit <- structure( list(trees = list(), support = matrix(1, nrow = 1L, ncol = 1L)), class = c("boostPM_fit", "list") ) testthat::expect_error( boostPM:::simulate.boostPM_fit(fit, nsim = 1L), "exactly two columns" ) fit$support <- matrix(c(1, 1), nrow = 1L) testthat::expect_error( boostPM:::simulate.boostPM_fit(fit, nsim = 1L), "positive width" ) }) testthat::test_that("simulation rejects negative sizes", { fit <- structure( list(trees = list(), support = matrix(c(0, 1), nrow = 1L)), class = c("boostPM_fit", "list") ) testthat::expect_error( boostPM:::simulate.boostPM_fit(fit, nsim = -1L), "non-negative" ) }) testthat::test_that("fitting handles node boundaries and round-off drift", { fit_raw_value <- function(value) { result <- boostPM:::do_boosting( matrix(value, nrow = 1L, ncol = 1L), 1, 0, 0, 1, 0, 0.1, 1, 2, 1, 1, 100, FALSE ) result } testthat::expect_no_error(right_boundary <- fit_raw_value(1)) testthat::expect_identical(right_boundary$residuals_boosting, matrix(1)) drift <- 16 * .Machine$double.eps testthat::expect_no_error(above <- fit_raw_value(1 + drift)) testthat::expect_no_error(below <- fit_raw_value(0 - drift)) testthat::expect_identical(above$residuals_boosting, matrix(1)) testthat::expect_identical(below$residuals_boosting, matrix(0)) testthat::expect_error( fit_raw_value(1.01), "beyond the floating-point tolerance" ) }) testthat::test_that("density evaluation rejects incompatible points", { fit <- structure( list(trees = list(), support = cbind(c(0, 0), c(1, 1))), class = c("boostPM_fit", "list") ) testthat::expect_error( stats::predict(fit, matrix(0.5, nrow = 1L, ncol = 1L)), "one column per support row" ) testthat::expect_error( stats::predict(fit, matrix(c(NA, 0.5), nrow = 1L)), "finite values" ) }) testthat::test_that("post-processing rejects malformed serialized trees", { malformed <- structure(list( trees = list(list( d = c(0L, -1L, -1L), l = c(0.5, -1), theta = c(0.5, -1, -1) )), support = matrix(c(0, 1), nrow = 1L) ), class = c("boostPM_fit", "list")) testthat::expect_error( stats::simulate(malformed, nsim = 1L), "equal non-zero lengths" ) malformed$trees[[1]] <- list( d = c(1L, -1L, -1L), l = c(0.5, -1, -1), theta = c(0.5, -1, -1) ) testthat::expect_error( stats::predict(malformed, matrix(0.5, ncol = 1L)), "dimension outside the support" ) })