Skip to content

Commit

Permalink
test split_by errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JackEdTaylor committed Jan 15, 2025
1 parent 0f28cbd commit 372df3b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/testthat/test-split_by_errors.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
context("split_by() errors")

# setup ----
dat <- data.frame(
a = c(1.0, 1.1, 1.3, 1.9, 2, 2.1, 2.2, 2.9, 3, 3.1, 3.3)
)

# general errors ----
testthat::test_that("general errors", {
testthat::expect_error({
dat |>
split_by(a, 2:1 ~ 2.1:2.5 ~ 3.2:4)
},
"lower bounds must be lower than upper bounds",
fixed = TRUE
)

testthat::expect_error({
dat |>
split_by(a, 1:2 ~ 2:2.5 ~ 3.2:4)
},
"overlapping levels - ensure that no value could fall into multiple levels",
fixed = TRUE
)

# test whether still detected when out of order
testthat::expect_error({
dat |>
split_by(a, 1:2 ~ 3.2:4 ~ 2:2.5)
},
"overlapping levels - ensure that no value could fall into multiple levels",
fixed = TRUE
)

})

0 comments on commit 372df3b

Please sign in to comment.