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_equal fails unless we set tolerance #1897

Closed
stla opened this issue Nov 9, 2023 · 3 comments
Closed

expect_equal fails unless we set tolerance #1897

stla opened this issue Nov 9, 2023 · 3 comments
Labels
bug an unexpected problem or unintended behavior expectation 🙀

Comments

@stla
Copy link

stla commented Nov 9, 2023

Hello,

library(Carlson)

nome <- function(m) {
  if(m == 0) {
    return(as.complex(0))
  }
  if(m == 1) {
    return(as.complex(1))
  }
  exp(-pi * elliptic_F(pi/2, 1-m) / elliptic_F(pi/2, m))
}

nome(-2)
# -0.06823783+0i

testthat::expect_equal(nome(-2), as.complex(-0.06823783))
# Erreur : nome(-2) (`actual`) not equal to as.complex(-0.06823783) (`expected`).
# 
# Re(actual) != Re(expected) but don't know how to show the difference

This works if we specifiy tolerance.

Latest versions of 'testthat', R and RStudio, Windows 10.

@hadley
Copy link
Member

hadley commented Nov 28, 2023

Minimal reprex:

testthat::local_edition(3)
x <- -6.82378277453383e-02-8e-17i
y <- as.complex(-0.06823783)

testthat::expect_equal(x, y)
#> Error: `x` (`actual`) not equal to `y` (`expected`).
#> 
#> Re(actual) != Re(expected) but don't know how to show the difference
waldo::compare(x, y)
#> `Re(old)`: -0.068237828
#> `Re(new)`: -0.068237830
#> 
#> `Im(old)`: -0.00000000000000008
#> `Im(new)`:  0.00000000000000000

Created on 2023-11-28 with reprex v2.0.2.9000

The waldo output looks fine so this does indeed appear to be a testthat problem.

@hadley hadley added bug an unexpected problem or unintended behavior expectation 🙀 labels Nov 28, 2023
@hadley
Copy link
Member

hadley commented Nov 29, 2023

Oops, no, it is a waldo problem with the default testthat tolerance:

x <- -6.82378277453383e-02-8e-17i
y <- as.complex(-0.06823783)

waldo::compare(x, y, tolerance = testthat::testthat_tolerance())
#> Re(old) != Re(new) but don't know how to show the difference

Created on 2023-11-29 with reprex v2.0.2.9000

@hadley
Copy link
Member

hadley commented Nov 29, 2023

Now tracked in r-lib/waldo#187

@hadley hadley closed this as completed Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior expectation 🙀
Projects
None yet
Development

No branches or pull requests

2 participants