Skip to content

Commit

Permalink
split out tests for reg_intervals()
Browse files Browse the repository at this point in the history
  • Loading branch information
hfrick committed Sep 18, 2024
1 parent 57d8697 commit 4a2a7bc
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 66 deletions.
14 changes: 0 additions & 14 deletions tests/testthat/_snaps/bootci.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,3 @@
Error in `bca_calc()`:
! All statistics have missing values.

# regression intervals

Code
skip_if(new_rng_snapshots)
set.seed(123)
int_2 <- reg_intervals(mpg ~ disp + wt, data = mtcars, filter = term == "wt",
model_fn = "glm", keep_reps = TRUE)
int_2
Output
# A tibble: 1 x 7
term .lower .estimate .upper .alpha .method .replicates
<chr> <dbl> <dbl> <dbl> <dbl> <chr> <list<tibble[,2]>>
1 wt -5.62 -3.46 -0.955 0.05 student-t [1,001 x 2]

14 changes: 14 additions & 0 deletions tests/testthat/_snaps/reg_intervals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# regression intervals

Code
skip_if(new_rng_snapshots)
set.seed(123)
int_2 <- reg_intervals(mpg ~ disp + wt, data = mtcars, filter = term == "wt",
model_fn = "glm", keep_reps = TRUE)
int_2
Output
# A tibble: 1 x 7
term .lower .estimate .upper .alpha .method .replicates
<chr> <dbl> <dbl> <dbl> <dbl> <chr> <list<tibble[,2]>>
1 wt -5.62 -3.46 -0.955 0.05 student-t [1,001 x 2]

52 changes: 0 additions & 52 deletions tests/testthat/test-bootci.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,58 +234,6 @@ test_that("bad input", {

# ------------------------------------------------------------------------------

test_that("regression intervals", {
skip_if_not_installed("broom")
skip_on_cran()

expect_error(
{
set.seed(1)
int_1 <- reg_intervals(mpg ~ disp + wt, data = mtcars)
},
regexp = NA
)

expect_equal(
names(int_1),
c("term", ".lower", ".estimate", ".upper", ".alpha", ".method")
)

expect_snapshot({
skip_if(new_rng_snapshots)
set.seed(123)
int_2 <- reg_intervals(
mpg ~ disp + wt,
data = mtcars,
filter = term == "wt",
model_fn = "glm",
keep_reps = TRUE
)
int_2
})

expect_equal(
names(int_2),
c("term", ".lower", ".estimate", ".upper", ".alpha", ".method", ".replicates")
)
expect_true(nrow(int_2) == 1)
expect_true(all(int_2$term == "wt"))


expect_error(
reg_intervals(mpg ~ disp + wt, data = mtcars, model_fn = "potato"),
"`model_fn` must be one of"
)
expect_error(
reg_intervals(mpg ~ disp + wt, data = mtcars, type = "random"),
"`type` must be one of"
)
expect_error(
reg_intervals(mpg ~ disp + wt, data = mtcars, alpha = "a"),
"must be a single numeric value"
)
})

test_that("compute intervals with additional grouping terms", {
skip_if_not_installed("broom")

Expand Down
51 changes: 51 additions & 0 deletions tests/testthat/test-reg_intervals.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
test_that("regression intervals", {
skip_if_not_installed("broom")
skip_on_cran()

expect_error(
{
set.seed(1)
int_1 <- reg_intervals(mpg ~ disp + wt, data = mtcars)
},
regexp = NA
)

expect_equal(
names(int_1),
c("term", ".lower", ".estimate", ".upper", ".alpha", ".method")
)

expect_snapshot({
skip_if(new_rng_snapshots)
set.seed(123)
int_2 <- reg_intervals(
mpg ~ disp + wt,
data = mtcars,
filter = term == "wt",
model_fn = "glm",
keep_reps = TRUE
)
int_2
})

expect_equal(
names(int_2),
c("term", ".lower", ".estimate", ".upper", ".alpha", ".method", ".replicates")
)
expect_true(nrow(int_2) == 1)
expect_true(all(int_2$term == "wt"))


expect_error(
reg_intervals(mpg ~ disp + wt, data = mtcars, model_fn = "potato"),
"`model_fn` must be one of"
)
expect_error(
reg_intervals(mpg ~ disp + wt, data = mtcars, type = "random"),
"`type` must be one of"
)
expect_error(
reg_intervals(mpg ~ disp + wt, data = mtcars, alpha = "a"),
"must be a single numeric value"
)
})

0 comments on commit 4a2a7bc

Please sign in to comment.