tests/testthat/test-autoplot-lifetable.R

library(lifecontingencies)

test_that("autoplot returns a ggplot for lifetable", {
  skip_if_not_installed("ggplot2")

  tbl <- new("lifetable", x = 0:3, lx = c(100, 90, 50, 10))
  p <- ggplot2::autoplot(tbl)

  expect_s3_class(p, "ggplot")
  expect_equal(p$labels$x, "Age")
  expect_equal(p$labels$y, "Number of survivors")
})

test_that("autoplot is inherited by actuarialtable", {
  skip_if_not_installed("ggplot2")

  tbl <- new(
    "actuarialtable",
    x = 0:3,
    lx = c(100, 90, 50, 10),
    interest = 0.03
  )
  p <- ggplot2::autoplot(tbl)

  expect_s3_class(p, "ggplot")
  expect_equal(p$labels$title, paste("Life table", tbl@name))
})

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.