tests/testthat/test-plot.R

test_that("fair_example dataset is a usable assessment object", {
  data(fair_example, package = "rfair")
  expect_s3_class(fair_example, "fair_assessment")
  s <- summary(fair_example)
  expect_true(all(c("F", "A", "I", "R", "FAIR") %in% s$category))
  expect_true(is.finite(s$percent[s$category == "FAIR"]))
})

test_that("plot.fair_assessment draws both types without error", {
  data(fair_example, package = "rfair")
  tmp <- tempfile(fileext = ".png")

  grDevices::png(tmp, width = 700, height = 450)
  res <- plot(fair_example)
  grDevices::dev.off()
  expect_s3_class(res, "fair_assessment")          # returns x invisibly
  expect_gt(file.size(tmp), 0)

  grDevices::png(tmp, width = 700, height = 650)
  expect_silent(plot(fair_example, type = "metric"))
  grDevices::dev.off()

  grDevices::png(tmp, width = 600, height = 560)
  res2 <- plot(fair_example, type = "sunburst")
  grDevices::dev.off()
  expect_s3_class(res2, "fair_assessment")
  expect_gt(file.size(tmp), 0)
})

test_that("plot validates its type argument", {
  data(fair_example, package = "rfair")
  expect_error(plot(fair_example, type = "nope"))
})

Try the rfair package in your browser

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

rfair documentation built on July 1, 2026, 5:07 p.m.