tests/testthat/test-ard_stats_wilcox_test_onesample.R

skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx"))

test_that("ard_stats_wilcox_test_onesample() works", {
  # first calculate an object to test against
  expect_silent(
    ard1 <- ard_stats_wilcox_test_onesample(
      cards::ADSL,
      variables = AGE,
      by = ARM,
      conf.level = 0.9,
      conf.int = TRUE,
      mu = 1
    )
  )

  # first check arguments passed and returned correctly
  expect_equal(
    cards::get_ard_statistics(
      ard1,
      group1_level %in% "Placebo"
    )[c("mu", "conf.level")],
    list(mu = 1, conf.level = 0.9)
  )
  # check results are correct
  expect_equal(
    cards::get_ard_statistics(
      ard1,
      group1_level %in% "Placebo"
    )[c("estimate", "conf.low", "conf.high", "p.value")],
    wilcox.test(
      cards::ADSL$AGE[cards::ADSL$ARM == "Placebo"],
      conf.level = 0.9,
      mu = 1,
      conf.int = TRUE
    ) |>
      broom::tidy() |>
      dplyr::select(c("estimate", "conf.low", "conf.high", "p.value")) |>
      as.list()
  )

  # test the structure is good
  expect_silent(cards::check_ard_structure(ard1))

  # empty tibble returned with no variables
  expect_equal(
    ard_stats_wilcox_test_onesample(
      cards::ADSL,
      variables = character(0)
    ),
    dplyr::tibble() |> cards::as_card()
  )
})

test_that("ard_stats_wilcox_test_onesample() follows ard structure", {
  expect_silent(
    ard_stats_wilcox_test_onesample(
      cards::ADSL,
      variables = AGE,
      by = ARM,
      conf.level = 0.9,
      conf.int = TRUE,
      mu = 1
    ) |>
      cards::check_ard_structure()
  )
})

Try the cardx package in your browser

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

cardx documentation built on Sept. 11, 2024, 9:12 p.m.