library(rootWishartHD)

# theta-scale CDF, including boundary values 0 and 1
x <- seq(0, 1, length.out = 5)

y1 <- try(doubleWishart(x, s = 5, n = 10, m = 10,
                        type = "double", verbose = FALSE), silent = TRUE)
y2 <- try(doubleWishart(x, p = 5, n = 10, m = 10,
                        type = "fixed", verbose = FALSE), silent = TRUE)
y3 <- try(doubleWishart(c(0.2, 0.7, 0.5), s = 5, n = 10, m = 10,
                        type = "arbitrary", verbose = FALSE), silent = TRUE)

expect_false(inherits(y1, "try-error"))
expect_false(inherits(y2, "try-error"))
expect_false(inherits(y3, "try-error"))
expect_equal(length(y3), 3)

# beta type II lambda-scale values must not be accepted by the raw CDF API
bad <- try(doubleWishart(c(0.5, 5000), s = 5, n = 10, m = 10,
                         verbose = FALSE), silent = TRUE)
expect_true(inherits(bad, "try-error"))

# p-value wrapper is the intended lambda-scale entry point
pv <- try(doubleWishart_pvalue(5000, s = 5, n = 10, m = 10,
                               input = "lambda", verbose = FALSE), silent = TRUE)
expect_false(inherits(pv, "try-error"))

# Critical values at the boundary Jacobi case m=n=0 should still bracket.
# This is a small proxy for dsb(50,49,48), where s=48 and m=n=0.
qa <- try(doubleWishart_qalpha(0.05, s = 5, m = 0, n = 0,
                               return = "theta", type = "double",
                               fast_try_double = FALSE,
                               verbose = FALSE, max_iter = 40), silent = TRUE)
expect_false(inherits(qa, "try-error"))
expect_true(is.finite(as.numeric(qa)) && as.numeric(qa) >= 0 && as.numeric(qa) <= 1)
