Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expect_comparison could use waldo to determine digits in the failure case? #2006

Open
MichaelChirico opened this issue Nov 1, 2024 · 1 comment

Comments

@MichaelChirico
Copy link
Contributor

MichaelChirico commented Nov 1, 2024

sprintf("%s is %s %s. Difference: %.3g", act$lab, msg, exp$lab, act$val - exp$val),

Motivation: imbs-hl/ranger#747

I know {waldo} has recently improved "what's the right number of digits to show when compare() fails", so presumably we could re-use that logic here, e.g. compare(act - exp, 0). The specifics may need to be more careful, but I think it's clearly not helpful to have expect_gt() fail with message "Difference: 0".

@hadley
Copy link
Member

hadley commented Nov 6, 2024

Or just inline min_digits()?

min_digits <- function(x, y, tolerance = default_tol()) {
  if (is.integer(x) && is.integer(y)) {
    return(0L)
  }

  attributes(x) <- NULL
  attributes(y) <- NULL

  n <- digits(abs(x - y))
  if (!is.null(tolerance)) {
    n <- min(n, digits(tolerance))
  }

  as.integer(n) + 1L
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants