Skip to content

Commit

Permalink
Add tests for brk_manual() and tab_dissect().
Browse files Browse the repository at this point in the history
  • Loading branch information
hughjonesd committed Jun 10, 2024
1 parent f041bbc commit 629e50f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions tests/testthat/test-breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test_that("brk_manual", {

expect_error(brk_res(brk_manual(c(1, 2, 2, 2, 3), rep(TRUE, 5))),
regexp = "equal")

expect_warning(brk_res(brk_manual(1:3, rep(TRUE, 3)), left = FALSE))
expect_warning(brk_res(brk_manual(1:3, rep(TRUE, 3)), close_end = FALSE))
})


Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test-labels.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

brackets <- function (x) paste0("(", x, ")")


test_that("lbl_manual and lbl_endpoint are defunct", {
lifecycle::expect_defunct(lbl_manual(letters))
lifecycle::expect_defunct(lbl_endpoint()(lbrk))
Expand Down Expand Up @@ -50,6 +47,7 @@ test_that("lbl_dash arguments", {
expect_equivalent(lbl_dash("-", first = "< {r}")(brk), c("< 2", "2-3"))
expect_equivalent(lbl_dash("-", last = "> {l}")(brk), c("1-2", "> 2"))

brackets <- function (x) paste0("(", x, ")")
expect_equivalent(
lbl_dash("-", fmt = brackets)(brk),
c("(1)-(2)", "(2)-(3)")
Expand Down Expand Up @@ -344,6 +342,7 @@ test_that("lbl_discrete arguments", {
c("(1)-(2)", "(3)-(5)")
)

brackets <- function (x) paste0("(", x, ")")
expect_equivalent(
lbl_discrete("-", fmt = brackets)(lbrk),
c("(1)-(2)", "(3)-(5)")
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,14 @@ test_that("tab_spikes", {
))
)
})


test_that("tab_dissect", {
expect_equivalent(
tab_dissect(c(1:5, rep(3, 2)), breaks = c(2, 4), n = 3),
table(factor(
c("[1, 2)", "[2, 4)", rep("{3}", 3), rep("[4, 5]", 2)),
levels = c("[1, 2)", "[2, 4)", "{3}", "[4, 5]")
))
)
})

0 comments on commit 629e50f

Please sign in to comment.