Skip to content

Commit

Permalink
Skip more tests on CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
koenderks committed Oct 4, 2023
1 parent f4a2865 commit 7fa3eb3
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/testthat/test-auditPrior.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test_that(desc = "(id: f2-v0.1.0-t2) Test for method = 'impartial'", {
})

test_that(desc = "(id: f2-v0.1.0-t3) Test for method = 'hyp'", {
testthat::skip_on_cran()
prior <- auditPrior(materiality = 0.05, conf.level = 0.95, method = "hyp", likelihood = "binomial", p.hmin = 0.3)
expect_equal(prior[["description"]]$alpha, 1)
expect_equal(prior[["description"]]$beta, 6.954, tolerance = 0.001)
Expand All @@ -60,6 +61,7 @@ test_that(desc = "(id: f2-v0.1.0-t3) Test for method = 'hyp'", {
})

test_that(desc = "(id: f2-v0.1.0-t4) Test for method = 'arm'", {
testthat::skip_on_cran()
prior <- auditPrior(materiality = 0.05, conf.level = 0.95, method = "arm", likelihood = "binomial", ir = 0.6, cr = 0.6)
expect_equal(prior[["description"]]$alpha, 1)
expect_equal(prior[["description"]]$beta, 20, tolerance = 0.001)
Expand All @@ -74,6 +76,7 @@ test_that(desc = "(id: f2-v0.1.0-t4) Test for method = 'arm'", {
})

test_that(desc = "(id: f2-v0.1.0-t5) Test for method = 'sample'", {
testthat::skip_on_cran()
prior <- auditPrior(materiality = 0.05, conf.level = 0.95, method = "sample", likelihood = "binomial", n = 30, x = 1)
expect_equal(prior[["description"]]$alpha, 2)
expect_equal(prior[["description"]]$beta, 29)
Expand All @@ -88,6 +91,7 @@ test_that(desc = "(id: f2-v0.1.0-t5) Test for method = 'sample'", {
})

test_that(desc = "(id: f2-v0.1.0-t6) Test for method = 'factor'", {
testthat::skip_on_cran()
prior <- auditPrior(materiality = 0.05, conf.level = 0.95, method = "factor", likelihood = "binomial", n = 30, x = 1, factor = 0.6)
expect_equal(prior[["description"]]$alpha, 1.6, tolerance = 0.001)
expect_equal(prior[["description"]]$beta, 17.4, tolerance = 0.001)
Expand Down Expand Up @@ -127,6 +131,7 @@ test_that(desc = "(id: f2-v0.4.0-t1) Test for method = 'impartial' with expected
# jfa version 0.5.0

test_that(desc = "(id: f2-v0.5.0-t1) Test for summary and print function", {
testthat::skip_on_cran()
prior <- auditPrior(conf.level = 0.95, likelihood = "binomial", method = "default")
invisible(capture.output(print(prior)))
invisible(capture.output(summary(prior)))
Expand All @@ -135,6 +140,7 @@ test_that(desc = "(id: f2-v0.5.0-t1) Test for summary and print function", {
})

test_that(desc = "(id: f2-v0.5.0-t2) Test for plot function", {
testthat::skip_on_cran()
prior <- auditPrior(conf.level = 0.95, likelihood = "binomial", method = "default", materiality = 0.05)
p <- plot(prior)
expect_equal(is.null(prior), FALSE)
Expand All @@ -154,6 +160,7 @@ test_that(desc = "(id: f2-v0.5.0-t2) Test for plot function", {
# jfa version 0.5.3

test_that(desc = "(id: f2-v0.5.3-t1) Test for bram method binomial", {
testthat::skip_on_cran()
N <- 20000
materiality <- 2000
expectedMisstatement <- 300
Expand All @@ -167,6 +174,7 @@ test_that(desc = "(id: f2-v0.5.3-t1) Test for bram method binomial", {
})

test_that(desc = "(id: f2-v0.5.3-t2) Test for bram method poisson", {
testthat::skip_on_cran()
N <- 20000
materiality <- 2000
expectedMisstatement <- 300
Expand All @@ -185,18 +193,21 @@ test_that(desc = "(id: f2-v0.5.3-t2) Test for bram method poisson", {
# jfa version 0.6.0

test_that(desc = "(id: f2-v0.6.0-t1) Test for param method binomial", {
testthat::skip_on_cran()
prior <- auditPrior(materiality = 0.05, likelihood = "binomial", method = "param", alpha = 5, beta = 10)
expect_equal(prior[["description"]]$alpha, 5)
expect_equal(prior[["description"]]$beta, 10)
})

test_that(desc = "(id: f2-v0.6.0-t2) Test for param method poisson", {
testthat::skip_on_cran()
prior <- auditPrior(materiality = 0.05, likelihood = "poisson", method = "param", alpha = 5, beta = 10)
expect_equal(prior[["description"]]$alpha, 5)
expect_equal(prior[["description"]]$beta, 10)
})

test_that(desc = "(id: f2-v0.6.0-t1) Test for param method hypergeometric", {
testthat::skip_on_cran()
prior <- auditPrior(materiality = 0.05, likelihood = "hypergeometric", method = "param", alpha = 5, beta = 10, N = 100)
expect_equal(prior[["description"]]$alpha, 5)
expect_equal(prior[["description"]]$beta, 10)
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-digit-test.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
context("Validation of function digit_test")

test_that(desc = "Print and plot call", {
testthat::skip_on_cran()
data("sinoForest")
res <- digit_test(x = sinoForest$value, check = "first", reference = "benford")
p <- plot(res)
Expand All @@ -32,6 +33,7 @@ test_that(desc = "Validate Derks et al. (2020)", {
})

test_that(desc = "Validate uniform distribution", {
testthat::skip_on_cran()
res <- digit_test(x = 1:9, check = "first", reference = "uniform")
expect_equal(as.numeric(res$n), 9)
expect_equal(as.numeric(res$statistic), 0)
Expand All @@ -40,6 +42,7 @@ test_that(desc = "Validate uniform distribution", {
})

test_that(desc = "Validate benford.analysis package first digits", {
testthat::skip_on_cran()
ba <- benford.analysis::benford(data = sinoForest$value, number.of.digits = 1)
dt <- digit_test(x = sinoForest$value, check = "first")
expect_equal(as.numeric(ba$bfd$data.dist.freq), as.numeric(dt$observed))
Expand All @@ -49,6 +52,7 @@ test_that(desc = "Validate benford.analysis package first digits", {
})

test_that(desc = "Validate benford.analysis package first and second digits", {
testthat::skip_on_cran()
ba <- benford.analysis::benford(data = sinoForest$value, number.of.digits = 2)
dt <- digit_test(x = sinoForest$value, check = "firsttwo")
expect_equal(as.numeric(ba$bfd$data.dist.freq), as.numeric(dt$observed))
Expand All @@ -58,13 +62,15 @@ test_that(desc = "Validate benford.analysis package first and second digits", {
})

test_that(desc = "Validate BenfordTests package first digits", {
testthat::skip_on_cran()
bt <- BenfordTests::chisq.benftest(x = sinoForest$value, digits = 1)
dt <- digit_test(x = sinoForest$value, check = "first")
expect_equal(as.numeric(bt$statistic), as.numeric(dt$statistic))
expect_equal(as.numeric(bt$p.value), as.numeric(dt$p.value))
})

test_that(desc = "Validate BeyondBenford package first digits", {
testthat::skip_on_cran()
bb <- BeyondBenford::chi2(sinoForest$value, mod = "ben", dig = 1, pval = 1)
dt <- digit_test(x = sinoForest$value, check = "first")
expect_equal(as.numeric(bb$chi2[2]), as.numeric(dt$statistic))
Expand All @@ -78,11 +84,13 @@ test_that(desc = "Validate Derks et al. (2020)", {
})

test_that(desc = "Validate uniform distribution", {
testthat::skip_on_cran()
res <- digit_test(x = 1:9, check = "first", reference = "uniform", prior = TRUE)
expect_equal(1 / as.numeric(res$bf), 22.77012458)
})

test_that(desc = "Validate benford.analysis package", {
testthat::skip_on_cran()
ba <- benford.analysis::benford(data = sinoForest$value, number.of.digits = 1)
dt <- digit_test(x = sinoForest$value, check = "first")
expect_equal(as.numeric(ba$bfd$data.dist.freq), as.numeric(dt$observed))
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-evaluation.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ test_that(desc = "(id: f3-v0.1.0-t7) Evaluation with stringer method", {
})

test_that(desc = "(id: f3-v0.1.0-t8) Evaluation with stringer.meikle method", {
testthat::skip_on_cran()
set.seed(1)
population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE), bookValue = runif(n = 1000, min = 100, max = 500))
jfaRes <- planning(conf.level = 0.95, materiality = 0.05, likelihood = "poisson")
Expand All @@ -105,6 +106,7 @@ test_that(desc = "(id: f3-v0.1.0-t8) Evaluation with stringer.meikle method", {
})

test_that(desc = "(id: f3-v0.1.0-t9) Evaluation with stringer.lta method", {
testthat::skip_on_cran()
set.seed(1)
population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE), bookValue = runif(n = 1000, min = 100, max = 500))
jfaRes <- planning(conf.level = 0.95, materiality = 0.05, likelihood = "poisson")
Expand All @@ -121,6 +123,7 @@ test_that(desc = "(id: f3-v0.1.0-t9) Evaluation with stringer.lta method", {
})

test_that(desc = "(id: f3-v0.1.0-t10) Evaluation with stringer.pvz method", {
testthat::skip_on_cran()
set.seed(1)
population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE), bookValue = runif(n = 1000, min = 100, max = 500))
jfaRes <- planning(conf.level = 0.95, materiality = 0.05, likelihood = "poisson")
Expand All @@ -137,6 +140,7 @@ test_that(desc = "(id: f3-v0.1.0-t10) Evaluation with stringer.pvz method", {
})

test_that(desc = "(id: f3-v0.1.0-t11) Evaluation with rohrbach method", {
testthat::skip_on_cran()
set.seed(1)
population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE), bookValue = runif(n = 1000, min = 100, max = 500))
jfaRes <- planning(conf.level = 0.95, materiality = 0.05, likelihood = "poisson")
Expand All @@ -147,6 +151,7 @@ test_that(desc = "(id: f3-v0.1.0-t11) Evaluation with rohrbach method", {
})

test_that(desc = "(id: f3-v0.1.0-t12) Evaluation with moment method", {
testthat::skip_on_cran()
set.seed(1)
population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE), bookValue = runif(n = 1000, min = 100, max = 500))
jfaRes <- planning(conf.level = 0.95, materiality = 0.05, likelihood = "poisson")
Expand All @@ -160,6 +165,7 @@ test_that(desc = "(id: f3-v0.1.0-t12) Evaluation with moment method", {
})

test_that(desc = "(id: f3-v0.1.0-t13) Evaluation with direct method", {
testthat::skip_on_cran()
data("BuildIt")
BuildIt$inSample <- c(rep(1, 100), rep(0, 3400))
BuildIt_sample <- subset(BuildIt, BuildIt$inSample == 1)
Expand All @@ -170,6 +176,7 @@ test_that(desc = "(id: f3-v0.1.0-t13) Evaluation with direct method", {
})

test_that(desc = "(id: f3-v0.1.0-t14) Evaluation with difference method", {
testthat::skip_on_cran()
data("BuildIt")
BuildIt$inSample <- c(rep(1, 100), rep(0, 3400))
BuildIt_sample <- subset(BuildIt, BuildIt$inSample == 1)
Expand All @@ -180,6 +187,7 @@ test_that(desc = "(id: f3-v0.1.0-t14) Evaluation with difference method", {
})

test_that(desc = "(id: f3-v0.1.0-t15) Evaluation with quotient method", {
testthat::skip_on_cran()
data("BuildIt")
BuildIt$inSample <- c(rep(1, 100), rep(0, 3400))
BuildIt_sample <- subset(BuildIt, BuildIt$inSample == 1)
Expand All @@ -200,6 +208,7 @@ test_that(desc = "(id: f3-v0.1.0-t16) Evaluation with regression method", {
})

test_that(desc = "(id: f3-v0.1.0-t17) Evaluation with Cox and Snell method", {
testthat::skip_on_cran()
set.seed(1)
population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE), bookValue = runif(n = 1000, min = 100, max = 500))
jfaRes <- planning(conf.level = 0.95, materiality = 0.05, expected = 0.025)
Expand All @@ -216,6 +225,7 @@ test_that(desc = "(id: f3-v0.1.0-t17) Evaluation with Cox and Snell method", {
# jfa version 0.3.0

test_that(desc = "(id: f3-v0.3.0-t1) Evaluation with counts and stringer method", {
testthat::skip_on_cran()
set.seed(1)
population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE), bookValue = runif(n = 1000, min = 100, max = 500))
jfaRes <- planning(conf.level = 0.95, materiality = 0.05, expected = 0.025)
Expand Down Expand Up @@ -250,6 +260,7 @@ test_that(desc = "(id: f3-v0.4.0-t1) Bayes factors", {
# jfa version 0.5.0

test_that(desc = "(id: f3-v0.5.0-t1) Test for mpu estimator", {
testthat::skip_on_cran()
sample <- data.frame(ID = 1:100, ist = rnorm(mean = 1000, n = 100))
sample$soll <- sample$ist
sample$ist[1] <- 120
Expand All @@ -261,6 +272,7 @@ test_that(desc = "(id: f3-v0.5.0-t1) Test for mpu estimator", {
})

test_that(desc = "(id: f3-v0.5.0-t1) Test for frequentist summary and print function", {
testthat::skip_on_cran()
set.seed(1)
population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE), bookValue = runif(n = 1000, min = 100, max = 500))
jfaRes <- planning(conf.level = 0.95, materiality = 0.05, likelihood = "poisson")
Expand All @@ -280,6 +292,7 @@ test_that(desc = "(id: f3-v0.5.0-t1) Test for frequentist summary and print func
})

test_that(desc = "(id: f3-v0.2.0-t2) Test for Bayesian summary function", {
testthat::skip_on_cran()
set.seed(1)
population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE), bookValue = runif(n = 1000, min = 100, max = 500))
jfaRes <- planning(conf.level = 0.95, materiality = 0.05, likelihood = "poisson")
Expand All @@ -294,6 +307,7 @@ test_that(desc = "(id: f3-v0.2.0-t2) Test for Bayesian summary function", {
})

test_that(desc = "(id: f3-v0.2.0-t4) Test for Bayesian plot function", {
testthat::skip_on_cran()
set.seed(1)
population <- data.frame(ID = sample(1000:100000, size = 1000, replace = FALSE), bookValue = runif(n = 1000, min = 100, max = 500))
samp <- selection(population, size = 100, units = "items", method = "random")$sample
Expand Down Expand Up @@ -367,6 +381,7 @@ test_that(desc = "(id: f3-v0.6.0-t2) Test Bayes factors for gamma prior", {
})

test_that(desc = "(id: f3-v0.6.0-t3) Test Bayes factors for beta-binomial prior", {
testthat::skip_on_cran()
# Compute a Bayes factor from a noninformative beta-binomial prior
BF <- evaluation(materiality = 0.03, n = 160, x = 1, prior = auditPrior(method = "default", likelihood = "hypergeometric", N.units = 1000))$posterior$hypotheses$bf.h1
expect_equal(BF, 943.4715321)
Expand Down Expand Up @@ -540,6 +555,7 @@ test_that(desc = "(id: f3-v0.6.5-t6) Validate poststratification with stan examp
})

test_that(desc = "(id: f3-v0.6.5-t7) Test evaluation with non-conjugate priors", {
testthat::skip_on_cran()
# Cannot test for consistency due to sampling differences on OS's
prior <- auditPrior(method = "param", likelihood = "normal", alpha = 0.025, beta = 0.05)
res <- evaluation(materiality = 0.03, x = 0, n = 53, prior = prior, method = "binomial")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-model-fairness.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
context("Validation of function model_fairness")

test_that(desc = "Benchmark against fairness package", {
testthat::skip_on_cran()
data("compas")
# Demographic parity
jfa_dp <- model_fairness(compas, "Ethnicity", "TwoYrRecidivism", "Predicted", privileged = "Caucasian", positive = "yes", metric = "dp")
Expand Down
Loading

0 comments on commit 7fa3eb3

Please sign in to comment.