tests/testthat/test-plots.R

library(testthat)

test_that("Plot ROCs", {
  set.seed(123)
  data <- EmpiricalCalibration::simulateControls(n = 50 * 3, trueLogRr = log(c(1, 2, 4)))
  fileName <- tempfile(fileext = ".png")

  plot <- plotRocsInjectedSignals(
    logRr = data$logRr, trueLogRr = data$trueLogRr, showAucs = TRUE,
    fileName = fileName
  )

  expect_false(is.null(plot))
  expect_true(file.exists(fileName))

  unlink(fileName)
})

test_that("Plot coverage", {
  set.seed(123)
  data <- EmpiricalCalibration::simulateControls(n = 50 * 3, trueLogRr = log(c(1, 2, 4)))
  fileName <- tempfile(fileext = ".png")

  plot <- plotCoverageInjectedSignals(
    logRr = data$logRr, seLogRr = data$seLogRr, trueLogRr = data$trueLogRr,
    fileName = fileName
  )

  expect_false(is.null(plot))
  expect_true(file.exists(fileName))

  unlink(fileName)
})

test_that("Plot controls", {
  set.seed(123)
  data <- EmpiricalCalibration::simulateControls(n = 50 * 3, trueLogRr = log(c(1, 2, 4)))
  fileName <- tempfile(fileext = ".png")

  plot <- plotControls(
    logRr = data$logRr, seLogRr = data$seLogRr, trueLogRr = data$trueLogRr,
    fileName = fileName
  )

  expect_false(is.null(plot))
  expect_true(file.exists(fileName))

  unlink(fileName)
})
OHDSI/MethodEvaluation documentation built on Feb. 19, 2025, 9:18 a.m.