test_that("gen_time works correctly", {
  x <- gen_time(mat_u, mat_f)
  x_r <- gen_time(mat_u, matR = mat_f)
  x_c <- gen_time(mat_u, matC = mat_c)
  x_fc <- gen_time(mat_u, matF = mat_f, matC = mat_c)
  x_rfc <- gen_time(mat_u, matR = mat_f + mat_c)
  x_precedence <- gen_time(mat_u, matR = mat_f, matF = mat_c, matC = mat_c)
  x_start <- gen_time(mat_u, mat_f)
  x_singular <- gen_time(mat_u_singular, mat_f)

  expect_length(x, 1L)
  expect_gt(x, 0)
  expect_identical(x, x_r)
  expect_gt(x_c, 0)
  expect_identical(x_fc, x_rfc)
  expect_identical(x, x_precedence)
  expect_length(x_start, 1L)
  expect_gt(x_start, 0)
  expect_identical(x_singular, NA_real_)

  x_r0 <- gen_time(mat_u, mat_f, method = "R0")

  expect_identical(x, x_r0)

  x_po <- gen_time(mat_u, mat_f, method = "age_diff")
  x_singular_po <- gen_time(mat_u_singular, mat_f, method = "age_diff")
  expect_length(x_po, 1L)
  expect_gt(x_po, 0)
  expect_identical(x_singular_po, NA_real_)

  x_co <- gen_time(mat_u, mat_f, method = "cohort")
  x_singular_co <- gen_time(mat_u_singular, mat_f, method = "cohort")
  expect_length(x_co, 1L)
  expect_gt(x_co, 0)
  expect_identical(x_singular_co, NA_real_)
})

test_that("gen_time warns and fails gracefully", {
  expect_warning(gen_time(mat_u_survissue, mat_f))
  expect_error(gen_time(mat_u_na, mat_f))
  expect_error(gen_time(mat_u, mat_f_na))
  expect_error(gen_time(mat_u, matR = mat_f_na))

  expect_error(gen_time(mat_u_na, mat_f, method = "age_diff"))
  expect_error(gen_time(mat_u, mat_f_na, method = "age_diff"))
  expect_error(gen_time(mat_u, matR = mat_f_na, method = "age_diff"))

  expect_warning(gen_time(mat_u_survissue, mat_f))
  expect_error(gen_time(mat_u_na, mat_f, method = "cohort"))
  expect_error(gen_time(mat_u, mat_f_na, method = "cohort"))
  expect_error(gen_time(mat_u, matR = mat_f_na, method = "cohort"))
})
