tests/testthat/test_validation.R

skip_if_not_installed("validate")

data("women")
v <- validate::validator(height / weight < 0.5, mean(height) >= 0)
cf <- validate::confront(women, v)

test_that("confrontation summary percentages are correct", {
  orig.summary <- validate::summary(cf)

  expect_equal(
    validation_summary(cf)[["Fails (%)"]],
    sprintf("%1.2f%%", orig.summary$fails / orig.summary$items * 100)
  )
})

test_that("confrontation details are correct", {
  results <- validation_details(cf, v, "V1", NA, women)
  results <- results[(length(results) - 2):length(results)]
  expect_equal(
    gsub("  +", " ", results),
    with(women[1:3, ], sprintf("%d %d %d %.7f", 1:3, height, weight, height / weight))
  )
})

Try the iNZightTools package in your browser

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

iNZightTools documentation built on Oct. 12, 2023, 5:06 p.m.