tests/testthat/test-report.htest-correlation.R

test_that("report.htest-correlation", {
  set.seed(123)
  r <- report(cor.test(iris$Sepal.Width, iris$Sepal.Length))
  expect_equal(as.report_table(r)$r, -0.117, tolerance = 0.01)

  set.seed(123)
  r <- cor.test(iris$Sepal.Width, iris$Sepal.Length, method = "spearman", exact = FALSE)
  r <- report(r)
  expect_equal(as.report_table(r)$rho, -0.166, tolerance = 0.01)

  set.seed(123)
  r <- report(cor.test(iris$Sepal.Width, iris$Sepal.Length, method = "kendall"))
  expect_equal(as.report_table(r)$tau, -0.077, tolerance = 0.01)

  # snapshot tests with a different dataset
  set.seed(123)
  expect_snapshot(variant = "windows", report(cor.test(mtcars$wt, mtcars$mpg)))

  set.seed(123)
  expect_snapshot(variant = "windows", report(suppressWarnings(cor.test(
    mtcars$wt, mtcars$mpg,
    method = "spearman"
  ))))

  set.seed(123)
  expect_snapshot(variant = "windows", report(suppressWarnings(cor.test(
    mtcars$wt, mtcars$mpg,
    method = "kendall"
  ))))
})

Try the report package in your browser

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

report documentation built on Sept. 11, 2024, 8:47 p.m.