Skip to content

Commit

Permalink
skip_on_cran() added to heavy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarneche committed Mar 29, 2023
1 parent 084aad4 commit d5d097f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 57 deletions.
1 change: 1 addition & 0 deletions tests/testthat/test-amend.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ library(dplyr)
data(manec_example)

test_that("input checks work correctly and return appropriate messages", {
skip_on_cran()
general_error <- paste(
"Nothing to amend, please specify a proper model to either add or drop, or",
"changes to loo_controls;\n Returning original model set."
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-bayesmanec_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test_that("predict is silent", {
})

test_that("predict/fitted is a matrix of appropriately name elements", {
skip_on_cran()
pred_p <- predict(manec_example)
expect_equal(class(pred_p), c("matrix", "array"))
expect_equal(dim(pred_p), c(100, 4))
Expand All @@ -19,12 +20,14 @@ test_that("predict/fitted is a matrix of appropriately name elements", {
})

test_that("plot returns null, is invisible, and is silent", {
skip_on_cran()
expect_null(plot(manec_example))
expect_silent(plot(manec_example))
expect_invisible(plot(manec_example))
})

test_that("rhat behaves as expected", {
skip_on_cran()
rhat_p <- suppressMessages(rhat(manec_example))
rhat2_p <- rhat(manec_example, rhat_cutoff = 1)
expect_message(rhat(manec_example, rhat_cutoff = 1))
Expand All @@ -33,6 +36,7 @@ test_that("rhat behaves as expected", {
})

test_that("summary behaves as expected", {
skip_on_cran()
summary.p <- suppressWarnings(summary(manec_example))
expect_equal(class(summary.p), "manecsummary")
expect_equal(names(summary.p), c("models", "family", "sample_size",
Expand All @@ -42,6 +46,7 @@ test_that("summary behaves as expected", {
})

test_that("formula behaves as expected", {
skip_on_cran()
expect_error(formula(manec_example))
expect_s3_class(formula(manec_example, "nec4param"), "bayesnecformula")
expect_s3_class(formula(manec_example, model = "nec4param"),
Expand All @@ -52,6 +57,7 @@ test_that("formula behaves as expected", {
})

test_that("model.frame behaves as expected", {
skip_on_cran()
expect_error(model.frame(manec_example))
expect_s3_class(model.frame(manec_example, "nec4param"),
"data.frame")
Expand Down
70 changes: 42 additions & 28 deletions tests/testthat/test-ecx.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
library(bayesnec)
library(dplyr)
library(brms)

data(manec_example)

test_that("prob_vals warnings behave as expected", {
ecx(manec_example, prob_vals = c(0.6, 0.1, 0.9),
type = "relative") %>%
expect_length(3) %>%
suppressWarnings
ecx(manec_example, prob_vals = 0.9, type = "relative") %>%
expect_error %>%
suppressWarnings
ecx(manec_example, prob_vals = c(0.6, 0.9, 0.1),
type = "relative") %>%
expect_error %>%
suppressWarnings
ecx(nec4param, prob_vals = c(0.6, 0.1, 0.9),
type = "relative") %>%
expect_length(3) %>%
suppressWarnings
expect_error(ecx(nec4param, prob_vals = 0.9, type = "relative"))
expect_error(ecx(nec4param, prob_vals = c(0.6, 0.9, 0.1),
skip_on_cran()
ecx(manec_example, prob_vals = c(0.6, 0.1, 0.9), precision = 10,
type = "relative") |>
expect_length(3) |>
suppressWarnings()
ecx(manec_example, prob_vals = 0.9, precision = 10, type = "relative") |>
expect_error() |>
suppressWarnings()
ecx(manec_example, prob_vals = c(0.6, 0.9, 0.1), precision = 10,
type = "relative") |>
expect_error() |>
suppressWarnings()
ecx(nec4param, prob_vals = c(0.6, 0.1, 0.9), precision = 10,
type = "relative") |>
expect_length(3) |>
suppressWarnings()
expect_error(ecx(nec4param, prob_vals = 0.9, type = "relative",
precision = 10))
expect_error(ecx(nec4param, prob_vals = c(0.6, 0.9, 0.1), precision = 10,
type = "relative"))
})

test_that("ecx_val warnings behave as expected", {
expect_error(ecx(manec_example, ecx_val = 0.9, type = "relative")) %>%
suppressWarnings
expect_error(ecx(nec4param, ecx_val = 0.9, type = "relative"))
skip_on_cran()
expect_error(
ecx(manec_example, ecx_val = 0.9, type = "relative", precision = 10)
) |>
suppressWarnings()
expect_error(
ecx(nec4param, ecx_val = 0.9, type = "relative", precision = 10)
)
})

test_that("ecx returns expected object types and arguments pass correctly", {
skip_on_cran()
ec50_summary <- ecx(manec_example, ecx_val = 50, type = "relative",
precision = 50)
ec50_summary2 <- ecx(manec_example, ecx_val = 50, type = "relative",
Expand All @@ -57,34 +64,41 @@ test_that("ecx returns expected object types and arguments pass correctly", {
})

test_that("works for bayesnecfit", {
ecx1 <- ecx(ecx4param)
skip_on_cran()
ecx1 <- ecx(ecx4param, precision = 10)
expect_equal(length(ecx1), 3)
expect_equal(names(ecx1), c("Q50", "Q2.5", "Q97.5"))
})

test_that("works for bayesmanecfit", {
ecx1 <- ecx(manec_example)
skip_on_cran()
ecx1 <- ecx(manec_example, precision = 10)
expect_equal(length(ecx1), 3)
expect_equal(names(ecx1), c("Q50", "Q2.5", "Q97.5"))
})

test_that("xform passes correctly", {
ecx1 <- ecx(ecx4param)
ecx2 <- ecx(ecx4param, xform = exp)
skip_on_cran()
ecx1 <- ecx(ecx4param, precision = 10)
ecx2 <- ecx(ecx4param, xform = exp, precision = 10)
expect_gt(ecx2[1], ecx1[2])
})

test_that("posterior passes correctly", {
ecx3 <- ecx(ecx4param, posterior = TRUE)
skip_on_cran()
ecx3 <- ecx(ecx4param, posterior = TRUE, precision = 10)
expect_equal(length(ecx3), 100)
})

test_that("prob_vals passes correctly", {
ecx4 <- ecx(ecx4param, prob_vals = c(0.5, 0.3, 0.7))
skip_on_cran()
ecx4 <- ecx(ecx4param, prob_vals = c(0.5, 0.3, 0.7), precision = 10)
expect_equal(names(ecx4), c("Q50", "Q30", "Q70"))
})

test_that("ecx_val passes correctly", {
ecx4 <- ecx(ecx4param, prob_vals = c(0.5, 0.3, 0.7), ecx_val = 20)
skip_on_cran()
ecx4 <- ecx(ecx4param, prob_vals = c(0.5, 0.3, 0.7), ecx_val = 20,
precision = 10)
expect_equal(names(ecx4), c("Q50", "Q30", "Q70"))
})
9 changes: 9 additions & 0 deletions tests/testthat/test-expand_classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fit1 <- manec_example$mod_fits[["nec4param"]]
fit2 <- manec_example$mod_fits[["ecx4param"]]

test_that("expand_nec defaults work for nec model", {
skip_on_cran()
nec_fit <- expand_nec(fit1, fit1$bayesnecformula, model = "nec4param") %>%
suppressWarnings
expect_equal(names(nec_fit), c("fit", "model", "init", "bayesnecformula",
Expand All @@ -20,6 +21,7 @@ test_that("expand_nec defaults work for nec model", {
})

test_that("expand_nec arguments work for nec model", {
skip_on_cran()
nec_fit <- expand_nec(fit1, fit1$bayesnecformula, model = "nec4param",
x_range = c(0.01, 4), precision = 20) %>%
suppressWarnings
Expand All @@ -36,6 +38,7 @@ test_that("expand_nec arguments work for nec model", {
})

test_that("expand_ecx defaults work for ecx model", {
skip_on_cran()
ecx_fit <- expand_nec(fit2, fit2$bayesnecformula, model = "ecx4param") %>%
suppressWarnings
expect_equal(names(ecx_fit), c("fit", "model", "init", "bayesnecformula",
Expand All @@ -51,6 +54,7 @@ test_that("expand_ecx defaults work for ecx model", {
})

test_that("expand_ecx arguments work for ecx model", {
skip_on_cran()
ecx_fit <- expand_nec(fit2, fit2$bayesnecformula, model = "ecx4param",
x_range = c(0.01, 4), precision = 20) %>%
suppressWarnings
Expand All @@ -67,6 +71,7 @@ test_that("expand_ecx arguments work for ecx model", {
})

test_that("expand_ecx sig_val argument work for ecx model", {
skip_on_cran()
ecx_fit_a <- expand_nec(fit2, fit2$bayesnecformula, model = "ecx4param") %>%
suppressWarnings
ecx_fit_b <- expand_nec(fit2, fit2$bayesnecformula, model = "ecx4param",
Expand All @@ -81,6 +86,7 @@ test_null <- NULL
tt2 <- tt1["nec4param"]

test_that("expand_manec warnings work correctly", {
skip_on_cran()
expect_error(expand_manec(test_null))
expect_message(expand_manec(tt2, formulas[["nec4param"]]),
"Only nec4param is fitted, no model averaging done.")
Expand All @@ -90,6 +96,7 @@ test_that("expand_manec warnings work correctly", {
})

test_that("expand_manec defaults work correctly", {
skip_on_cran()
tt3 <- expand_manec(tt1, formulas) %>%
suppressMessages %>%
suppressWarnings
Expand All @@ -99,6 +106,7 @@ test_that("expand_manec defaults work correctly", {
})

test_that("expand_manec defaults work correctly", {
skip_on_cran()
tt4 <- expand_manec(tt1, formulas, x_range = c(0.01, 4), precision = 20) %>%
suppressMessages %>%
suppressWarnings
Expand All @@ -111,6 +119,7 @@ test_that("new loo_controls are incorporated", {
get_new_method <- function(x) {
attributes(x$mod_stats$wi)$method
}
skip_on_cran()
expand_manec(tt1, formulas) %>%
get_new_method %>%
expect_null %>%
Expand Down
76 changes: 47 additions & 29 deletions tests/testthat/test-nsec.R
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
library(bayesnec)
library(dplyr)
library(brms)

data(manec_example)

test_that("prob_vals warnings behave as expected", {
expect_length(nsec(manec_example, prob_vals = c(0.6, 0.1, 0.9)), 3) %>%
suppressWarnings
expect_error(nsec(manec_example, prob_vals = 0.9)) %>%
suppressWarnings
expect_error(nsec(manec_example, prob_vals = c(0.6, 0.9, 0.1))) %>%
suppressWarnings
expect_length(nsec(nec4param, prob_vals = c(0.6, 0.1, 0.9)), 3)
expect_error(nsec(nec4param, prob_vals = 0.9))
expect_error(nsec(nec4param, prob_vals = c(0.6, 0.9, 0.1)))
skip_on_cran()
expect_length(
nsec(manec_example, prob_vals = c(0.6, 0.1, 0.9), precision = 10), 3
) |>
suppressWarnings()
expect_error(
nsec(manec_example, prob_vals = 0.9, precision = 10)
) |>
suppressWarnings()
expect_error(
nsec(manec_example, prob_vals = c(0.6, 0.9, 0.1), precision = 10)
) |>
suppressWarnings()
expect_length(
nsec(nec4param, prob_vals = c(0.6, 0.1, 0.9), precision = 10), 3
)
expect_error(nsec(nec4param, prob_vals = 0.9, precision = 10))
expect_error(nsec(nec4param, prob_vals = c(0.6, 0.9, 0.1), precision = 10))
})

test_that(paste0("nsec returns expected object types and precision is",
" passing correctly"), {
nsec_summary <- nsec(manec_example, sig_val = 0.01, precision = 50) %>%
suppressWarnings
skip_on_cran()
nsec_summary <- nsec(manec_example, sig_val = 0.01, precision = 50) |>
suppressWarnings()
nsec_summary2 <- nsec(manec_example, sig_val = 0.01, precision = 50,
xform = exp) %>%
suppressWarnings
xform = exp) |>
suppressWarnings()
nsec_posterior <- nsec(manec_example, sig_val = 0.01,
posterior = TRUE, precision = 50) %>%
suppressWarnings
nsecn_summary <- nsec(nec4param, sig_val = 0.01, precision = 50) %>%
suppressWarnings
posterior = TRUE, precision = 50) |>
suppressWarnings()
nsecn_summary <- nsec(nec4param, sig_val = 0.01, precision = 50) |>
suppressWarnings()
nsecn_summary2 <- nsec(nec4param, sig_val = 0.01, precision = 50,
xform = exp) %>%
suppressWarnings
xform = exp) |>
suppressWarnings()
nsecn_posterior <- nsec(nec4param, sig_val = 0.01,
posterior = TRUE, precision = 50) %>%
suppressWarnings
posterior = TRUE, precision = 50) |>
suppressWarnings()
expect_equal(length(nsec_summary), 3)
expect_gt(length(nsec_posterior), 3)
expect_equal(length(nsecn_summary), 3)
Expand All @@ -44,35 +55,42 @@ test_that(paste0("nsec returns expected object types and precision is",
})

test_that("works for bayesnecfit", {
nsec1 <- nsec(ecx4param)
skip_on_cran()
nsec1 <- nsec(ecx4param, precision = 10)
expect_equal(length(nsec1), 3)
expect_equal(names(nsec1), c("Q50", "Q2.5", "Q97.5"))
})

test_that("works for bayesmanecfit", {
nsec1 <- nsec(manec_example) %>%
suppressWarnings
skip_on_cran()
nsec1 <- nsec(manec_example, precision = 10) |>
suppressWarnings()
expect_equal(length(nsec1), 3)
expect_equal(names(nsec1), c("Q50", "Q2.5", "Q97.5"))
})

test_that("xform passes correctly", {
nsec1 <- nsec(ecx4param)
nsec2 <- nsec(ecx4param, xform = exp)
skip_on_cran()
nsec1 <- nsec(ecx4param, precision = 10)
nsec2 <- nsec(ecx4param, xform = exp, precision = 10)
expect_gt(nsec2[1], nsec1[2])
})

test_that("posterior passes correctly", {
nsec3 <- nsec(ecx4param, posterior = TRUE)
skip_on_cran()
nsec3 <- nsec(ecx4param, posterior = TRUE, precision = 10)
expect_equal(length(nsec3), 100)
})

test_that("prob_vals passes correctly", {
nsec4 <- nsec(ecx4param, prob_vals = c(0.5, 0.3, 0.7))
skip_on_cran()
nsec4 <- nsec(ecx4param, prob_vals = c(0.5, 0.3, 0.7), precision = 10)
expect_equal(names(nsec4), c("Q50", "Q30", "Q70"))
})

test_that("sig_val passes correctly", {
nsec4 <- nsec(ecx4param, prob_vals = c(0.5, 0.3, 0.7), sig_val = 0.05)
skip_on_cran()
nsec4 <- nsec(ecx4param, prob_vals = c(0.5, 0.3, 0.7), sig_val = 0.05,
precision = 10)
expect_equal(names(nsec4), c("Q50", "Q30", "Q70"))
})

0 comments on commit d5d097f

Please sign in to comment.