tests/testthat/test-input-validation.R

test_that("invalid public inputs fail early with informative errors", {
  expect_error(gof_test(matrix(1:6, ncol=2), function() 0.5, rnull_u2, B=2, maxProcessor=1), "pnull must have 1 argument")
  bad_ts <- function(x, pnull, param) c(0.25)
  expect_error(gof_test(rnull_u2(), pnull_u2, rnull_u2, TS=bad_ts, B=2, maxProcessor=1), "named numeric vector")
  expect_error(gof_test(rnull_u2(), pnull_u2, rnull_u2, doMethods="not-a-method", B=2, maxProcessor=1), "Unknown method")
  expect_error(gof_test(rnull_u2(), pnull_u2, rnull_u2, B=-1, maxProcessor=1), "B must be")
  expect_error(gof_power(pnull_u2, rnull_u2, ralt_u2, 1.2, alpha=1, B=2, maxProcessor=1), "alpha must be")
})

test_that("discrete data use the same classifier in validation and testing", {
  x <- rnull_binom()
  checked <- MDgof:::check.functions(pnull_binom, rnull_binom, x=x)
  expect_false(checked$Continuous)
  out <- gof_test(x, pnull_binom, rnull_binom, doMethods="K", B=2, maxProcessor=1)
  expect_gof_contract(out)
})

test_that("With.p.value power accepts a supplied p-value statistic", {
  pvalue_ts <- function(x, pnull, param) c(P=0.5)
  expect_error(gof_power(pnull_u2, rnull_u2, ralt_u2, 1.2, With.p.value=TRUE, B=2, maxProcessor=1), "requires a user-supplied TS")
  out <- gof_power(pnull_u2, rnull_u2, ralt_u2, c(1.0, 1.2), TS=pvalue_ts, With.p.value=TRUE, B=2, maxProcessor=1)
  expect_probability_output(out)
})

Try the MDgof package in your browser

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

MDgof documentation built on Sept. 23, 2026, 5:08 p.m.