Skip to content

Commit 4a6bd05

Browse files
authored
Merge pull request #540 from tidymodels/self-contained-tests
Make tests more self-contained
2 parents bdf12e1 + 9a27ae4 commit 4a6bd05

File tree

2 files changed

+284
-169
lines changed

2 files changed

+284
-169
lines changed

tests/testthat/test-bootci.R

+32-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
n <- 1000
2-
mu <- 10
3-
sigma <- 1
4-
5-
set.seed(888)
6-
rand_nums <- rnorm(n, mu, sigma)
7-
dat <- data.frame(x = rand_nums)
8-
9-
set.seed(456765)
10-
bt_norm <-
11-
bootstraps(dat, times = 1000, apparent = TRUE) %>%
12-
dplyr::mutate(
13-
stats = purrr::map(splits, ~ get_stats(.x))
14-
)
15-
161
test_that("Bootstrap estimate of mean is close to estimate of mean from normal distribution", {
172
skip_if_not_installed("broom")
183
skip_on_cran()
4+
5+
set.seed(888)
6+
rand_nums <- rnorm(n = 1000, mean = 10, sd = 1)
7+
dat <- data.frame(x = rand_nums)
8+
9+
set.seed(456765)
10+
bt_norm <- bootstraps(dat, times = 1000, apparent = TRUE) %>%
11+
dplyr::mutate(
12+
stats = purrr::map(splits, ~ get_stats(.x))
13+
)
14+
1915
ttest <- broom::tidy(t.test(rand_nums))
2016
ttest_lower_conf <- broom::tidy(t.test(rand_nums, conf.level = 0.8))
2117
single_pct_res <- int_pctl(bt_norm, stats)
@@ -156,6 +152,9 @@ test_that("Upper & lower confidence interval does not contain NA", {
156152
test_that(
157153
"Sufficient replications needed to sufficiently reduce Monte Carlo sampling Error for BCa method",
158154
{
155+
set.seed(888)
156+
rand_nums <- rnorm(n = 1000, mean = 10, sd = 1)
157+
dat <- data.frame(x = rand_nums)
159158
set.seed(456765)
160159
bt_small <-
161160
bootstraps(dat, times = 10, apparent = TRUE) %>%
@@ -172,8 +171,12 @@ test_that(
172171
test_that(
173172
"Sufficient replications needed to sufficiently reduce Monte Carlo sampling Error for BCa method",
174173
{
175-
skip("until we don't get a message about loading purrr in the snapshot in R CMD check hard")
174+
skip("#539 message about loading purrr in the snapshot in R CMD check hard")
176175
# unskip this by moving the expectation back into the test_that block above
176+
177+
set.seed(888)
178+
rand_nums <- rnorm(n = 1000, mean = 10, sd = 1)
179+
dat <- data.frame(x = rand_nums)
177180
set.seed(456765)
178181
bt_small <-
179182
bootstraps(dat, times = 10, apparent = TRUE) %>%
@@ -187,6 +190,9 @@ test_that(
187190
)
188191

189192
test_that("bad input", {
193+
set.seed(888)
194+
rand_nums <- rnorm(n = 1000, mean = 10, sd = 1)
195+
dat <- data.frame(x = rand_nums)
190196
set.seed(456765)
191197
bt_small <-
192198
bootstraps(dat, times = 10, apparent = TRUE) %>%
@@ -220,6 +226,16 @@ test_that("bad input", {
220226
int_bca(vfold_cv(mtcars))
221227
})
222228

229+
set.seed(888)
230+
rand_nums <- rnorm(n = 1000, mean = 10, sd = 1)
231+
dat <- data.frame(x = rand_nums)
232+
233+
set.seed(456765)
234+
bt_norm <- bootstraps(dat, times = 1000, apparent = TRUE) %>%
235+
dplyr::mutate(
236+
stats = purrr::map(splits, ~ get_stats(.x))
237+
)
238+
223239
bad_bt_norm <-
224240
bt_norm %>%
225241
mutate(stats = purrr::map(stats, ~ .x[, 1:2]))

0 commit comments

Comments
 (0)