test_that("baseline_hazard works correctly", { t <- seq(0.1, 2, by = 0.1) par <- c(1.5, 0.8) bh <- baseline_hazard(t, par) expect_length(bh$H0, length(t)) expect_length(bh$h0, length(t)) expect_true(all(bh$H0 >= 0)) expect_true(all(bh$h0 >= 0)) }) test_that("alpha_power_functions works correctly", { t <- 1:5 eta <- 0 theta <- 0.5 par <- c(1.5, 0.8) gf <- alpha_power_functions(t, eta, theta_frailty = theta, par = par) expect_length(gf$S, length(t)) expect_length(gf$f, length(t)) expect_length(gf$h, length(t)) expect_length(gf$H, length(t)) expect_true(all(gf$S >= 0 & gf$S <= 1)) expect_true(all(gf$f >= 0)) expect_true(all(gf$h >= 0)) expect_true(all(gf$H >= 0)) }) test_that("r_alpha_power generates valid samples", { set.seed(123) n <- 50 par <- c(1.5, 0.8) samples <- r_alpha_power(n, alpha = par[1], beta = par[2]) expect_length(samples, n) expect_true(all(samples > 0)) expect_true(all(is.finite(samples))) }) test_that("fit_alpha_power works with simple data", { set.seed(123) dat <- r_alpha_power_reg(50, par = c(1.5, 0.8), theta = 0.3, cen_type = "right", cen_rate = 0.2) fit <- fit_alpha_power(dat$time, dat$status, frailty = TRUE) expect_s3_class(fit, "alpha_power_fit") expect_true(fit$logLik < 0) expect_true(fit$AIC > 0) expect_true(fit$BIC > 0) }) test_that("predict_alpha_power and residuals_alpha_power work", { set.seed(123) dat <- r_alpha_power_reg(50, par = c(1.5, 0.8), theta = 0.3, cen_type = "right", cen_rate = 0.2) fit <- fit_alpha_power(dat$time, dat$status) pred <- predict_alpha_power(fit, type = "survival") expect_true(is.matrix(pred$survival)) expect_true(all(pred$survival >= 0 & pred$survival <= 1)) res <- residuals_alpha_power(fit) expect_true(is.list(res)) expect_true("cox_snell" %in% names(res)) expect_true("martingale" %in% names(res)) expect_true("deviance" %in% names(res)) expect_length(res$cox_snell, length(dat$time)) })