Skip to content

Commit

Permalink
test: add some check tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiAragaki committed Nov 5, 2023
1 parent b013605 commit ee483d3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ check_index <- function(x) {
}

check_abs <- function(x) {
if (!is.numeric(x)) rlang::abort("abs must be numeric")
if (any(x < 0)) rlang::warn("Negative values found in .abs")
if (!is.numeric(x)) rlang::abort("`.abs` must be numeric")
if (any(x < 0)) rlang::warn("Negative values found in `.abs`")
if (any(is.na(x))) rlang::warn("NA values found in `.abs`")
}

Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test-check.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})

test_that("check_has_cols works", {
df <- data.frame(a = "apple", b = "bee", c = "cow")
expect_no_error(check_has_cols(df, c("a", "b"), "and"))
expect_no_error(check_has_cols(df, c("a", "z"), "or"))
expect_error(check_has_cols(df, c("a", "z"), "and"))
expect_error(check_has_cols(df, c("z"), "or"))
})

test_that("check_index works", {
expect_error(check_index("1"))
expect_no_error(check_index(1))
expect_no_error(check_index(NA_integer_))
})

test_that("check_abs works", {
expect_error(check_abs(c("1", 2)), "`\\.abs` must be numeric")
expect_no_error(check_abs(c(0, 1)))
expect_warning(check_abs(c(-0.1, 0)), "Negative values found in `\\.abs`")
expect_error(check_abs(c(0, NA)))
})

0 comments on commit ee483d3

Please sign in to comment.