Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests more self-contained #540

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions tests/testthat/test-bootci.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
n <- 1000
mu <- 10
sigma <- 1

set.seed(888)
rand_nums <- rnorm(n, mu, sigma)
dat <- data.frame(x = rand_nums)

set.seed(456765)
bt_norm <-
bootstraps(dat, times = 1000, apparent = TRUE) %>%
dplyr::mutate(
stats = purrr::map(splits, ~ get_stats(.x))
)

test_that("Bootstrap estimate of mean is close to estimate of mean from normal distribution", {
skip_if_not_installed("broom")
skip_on_cran()

set.seed(888)
rand_nums <- rnorm(n = 1000, mean = 10, sd = 1)
dat <- data.frame(x = rand_nums)

set.seed(456765)
bt_norm <- bootstraps(dat, times = 1000, apparent = TRUE) %>%
dplyr::mutate(
stats = purrr::map(splits, ~ get_stats(.x))
)

ttest <- broom::tidy(t.test(rand_nums))
ttest_lower_conf <- broom::tidy(t.test(rand_nums, conf.level = 0.8))
single_pct_res <- int_pctl(bt_norm, stats)
Expand Down Expand Up @@ -156,6 +152,9 @@ test_that("Upper & lower confidence interval does not contain NA", {
test_that(
"Sufficient replications needed to sufficiently reduce Monte Carlo sampling Error for BCa method",
{
set.seed(888)
rand_nums <- rnorm(n = 1000, mean = 10, sd = 1)
dat <- data.frame(x = rand_nums)
set.seed(456765)
bt_small <-
bootstraps(dat, times = 10, apparent = TRUE) %>%
Expand All @@ -172,8 +171,12 @@ test_that(
test_that(
"Sufficient replications needed to sufficiently reduce Monte Carlo sampling Error for BCa method",
{
skip("until we don't get a message about loading purrr in the snapshot in R CMD check hard")
skip("#539 message about loading purrr in the snapshot in R CMD check hard")
# unskip this by moving the expectation back into the test_that block above

set.seed(888)
rand_nums <- rnorm(n = 1000, mean = 10, sd = 1)
dat <- data.frame(x = rand_nums)
set.seed(456765)
bt_small <-
bootstraps(dat, times = 10, apparent = TRUE) %>%
Expand All @@ -187,6 +190,9 @@ test_that(
)

test_that("bad input", {
set.seed(888)
rand_nums <- rnorm(n = 1000, mean = 10, sd = 1)
dat <- data.frame(x = rand_nums)
set.seed(456765)
bt_small <-
bootstraps(dat, times = 10, apparent = TRUE) %>%
Expand Down Expand Up @@ -220,6 +226,16 @@ test_that("bad input", {
int_bca(vfold_cv(mtcars))
})

set.seed(888)
rand_nums <- rnorm(n = 1000, mean = 10, sd = 1)
dat <- data.frame(x = rand_nums)

set.seed(456765)
bt_norm <- bootstraps(dat, times = 1000, apparent = TRUE) %>%
dplyr::mutate(
stats = purrr::map(splits, ~ get_stats(.x))
)

bad_bt_norm <-
bt_norm %>%
mutate(stats = purrr::map(stats, ~ .x[, 1:2]))
Expand Down
Loading
Loading