Skip to content

Commit

Permalink
Responding to review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Puzzled-Face committed Oct 16, 2023
1 parent 6c9bf09 commit c36809b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions R/checkmate.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ NULL
#' provided in `...` with every other object in `...` and returns `TRUE` if all
#' comparisons are equal within a given tolerance and `FALSE` otherwise.
#'
#' @param ... (`numeric`)\cr vectors to be compared
#' @param ... (`numeric`)\cr vectors to be compared.
#' @param tol (`numeric`)\cr the maximum difference to be tolerated when
#' judging equality
#' judging equality.
#'
#' @note If there are any missing or infinite values in `...`, this function
#' returns `FALSE`, regardless of the values of other elements in `...`.
#'
#' @note If elements in `...` are not all of the same length, `FALSE` is returned.
#'
#' @return TRUE if all element-by-element differences are less than `tolerance`
#' @return `TRUE` if all element-by-element differences are less than `tolerance`
#' in magnitude, `FALSE` otherwise.
#' @seealso [`assertions`] for more details.
#'
Expand Down Expand Up @@ -72,23 +72,20 @@ check_equal <- function(..., tol = sqrt(.Machine$double.eps)) {
return("Not all numeric")
}

rv <- test_true(
all_ok <- test_true(
all(
sapply(
2:length(dot_args),
function(z) abs(dot_args[[1]] - dot_args[[z]]) < tol
)
)
)
if (rv) {
if (all_ok) {
return(TRUE)
} else {
return("Not all equal")
}
"Not all equal"
}

# assert equality

#' Assert That All Arguments Are Equal
#'
#' @description `r lifecycle::badge("experimental")`
Expand All @@ -112,11 +109,15 @@ check_equal <- function(..., tol = sqrt(.Machine$double.eps)) {
#' @inheritParams checkmate::assert_numeric
#'
#' @export
#' @rdname check_equal
#' @examples
#' assert_equal(1:2, 1:2) # no error
#' assert_equal(0.01, 0.02, tol = 0.05) # no error
# nolint start
assert_equal <- function(..., tol = sqrt(.Machine$double.eps), .var.name = vname(x), add = NULL) {
# assert_equal <- makeAssertionFunction(check_equal) fails with error "Error
# in `checkmate::makeAssertion(..., res, .var.name, add)`: unused argument
# (add)", possibly because of the use of ... in check_equal.
res <- check_equal(..., tol = tol)
makeAssertion(list(...), res, .var.name, add)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-checkmate.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_that("check_equal works correctly", {
expect_equal(check_equal(1, c(1, 1)), "Not all of same length")
})

# assert_equal
# assert_equal ----
test_that("assert_equal works correctly", {
expect_invisible(assert_equal(1:2, 1:2))
expect_error(assert_equal(1:2, 2:3), "Assertion on 'x' failed: Not all equal.")
Expand Down

0 comments on commit c36809b

Please sign in to comment.