tests/testthat/test-legacy-rng.R

library(testthat)
library(lifecontingencies)

data(soa08Act)
context("Legacy random generation regression tests")

test_that("random-life generation supports historical abbreviations", {
  set.seed(123); expect_no_error(rLife(2, soa08Act, x = 0, k = 1, type = "T"))
  set.seed(123); expect_no_error(rLife(2, soa08Act, x = 0, k = 1, type = "cont"))
  set.seed(123); expect_no_error(rLife(2, soa08Act, x = 0, k = 1, type = "Kx"))
  set.seed(123); expect_no_error(rLife(2, soa08Act, x = 0, k = 1, type = "cur"))
  expect_no_error(rLifexyz(3, list(soa08Act, soa08Act), x = 33:34, k = 1, type = "cont"))
  set.seed(123)
  expect_no_error(rLifeContingenciesXyz(
    n = 5, lifecontingency = "Axyz", tablesList = list(soa08Act, soa08Act),
    x = 59:60, t = 30, m = 0, k = 1, status = "j"
  ))
  set.seed(123)
  expect_no_error(rLifeContingenciesXyz(
    n = 5, lifecontingency = "Axyz", tablesList = list(soa08Act, soa08Act),
    x = 59:60, t = 30, m = 0, k = 1, status = "joint"
  ))
  expect_no_error(getLifecontingencyPvXyz(
    deathsTimeXyz = matrix(c(50,50,51,43,44,22,12,56,20,24,53,12), ncol = 2),
    lifecontingency = "axyz", tablesList = list(soa08Act, soa08Act), i = 0.03,
    t = 30, x = c(40,50), m = 0, k = 1, status = "la"
  ))
})

test_that("invalid random-generation types are rejected", {
  expect_error(rLifexyz(3, list(soa08Act, soa08Act), x = 33:34, k = 1, type = "toto"))
})

Try the lifecontingencies package in your browser

Any scripts or data that you put into this service are public.

lifecontingencies documentation built on Aug. 24, 2026, 1:07 a.m.