test_that("c_effective recovers SIR formula when sigma dominates", {
  pars <- seair_params(beta = 1, sigma = 100, kappa = 0.1,
                       gamma_A = 0.1, gamma_I = 0.2,
                       alpha = 1, delta = 1)
  ce <- c_effective(pars)
  expected <- 1 / (pars$kappa + pars$gamma_A) +
    pars$kappa / ((pars$kappa + pars$gamma_A) * pars$gamma_I)
  expect_equal(ce, expected, tolerance = 1e-12)
})

test_that("R0 is independent of sigma", {
  m <- seq(0, 1, length.out = 201)
  f <- stats::dbeta(m, 2, 3)
  pars1 <- seair_params(beta = 1, sigma = 0.1, kappa = 0.2,
                        gamma_A = 0.1, gamma_I = 0.13,
                        alpha = 0.5, delta = 0.3)
  pars2 <- seair_params(beta = 1, sigma = 10,  kappa = 0.2,
                        gamma_A = 0.1, gamma_I = 0.13,
                        alpha = 0.5, delta = 0.3)
  expect_equal(R0_seair(pars1, f, m),
               R0_seair(pars2, f, m),
               tolerance = 1e-10)
})

test_that("final_size returns zero when R0 <= 1", {
  pars <- seair_params(beta = 0.01, sigma = 0.3, kappa = 0.2,
                       gamma_A = 0.5, gamma_I = 0.5,
                       alpha = 0.1, delta = 0.1)
  fs <- final_size(pars, function(m) 6 * m * (1 - m))
  expect_lte(fs$R0, 1)
  expect_equal(fs$R_inf, 0)
})

test_that("final_size returns a valid supercritical final size", {
  m <- seq(0, 1, length.out = 51)
  f <- stats::dbeta(m, 2, 2)
  pars <- seair_params(beta = 2, sigma = 0.3, kappa = 0.2,
                       gamma_A = 0.1, gamma_I = 0.2,
                       alpha = 0.5, delta = 0.5)
  fs <- final_size(pars, f, m_grid = m)
  expect_true(fs$converged)
  expect_gt(fs$R0, 1)
  expect_gt(fs$R_inf, 0)
  expect_lt(fs$R_inf, 1)
})


test_that("final_size_general returns zero when R0 <= 1 and I_seed = 0", {
  pars <- seair_params(beta = 0.01, sigma = 0.3, kappa = 0.2,
                       gamma_A = 0.5, gamma_I = 0.5,
                       alpha = 0.1, delta = 0.1)
  fs <- final_size_general(pars,
                           function(m) 6 * m * (1 - m),
                           I_seed = 0)
  expect_lte(fs$R0, 1)
  expect_equal(fs$R_inf, 0)
})
