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

Catch v2.0.1 - CHECK(-0.0019569472 == Approx(0.0).epsilon(0.1)); does not work #1096

Closed
mariusz102102 opened this issue Nov 12, 2017 · 3 comments

Comments

@mariusz102102
Copy link

mariusz102102 commented Nov 12, 2017

Description

Regression v2.0.1 compare v1.9.7

Steps to reproduce

TEST_CASE("Test weight")
{
    CHECK(-0.0019569472 == Approx(0.0).epsilon(0.1));
}
g:\test\test.cpp(91): FAILED:
  CHECK( -0.0019569472 == Approx(0.0).epsilon(0.1) )
with expansion:
  -0.0019569472 == Approx( 0.0 )

Extra information

Below test case fails on v2.0.1 passed in catch v1.9.7

  • Catch version: v2.0.1
  • Operating System: *Windows 10 **
  • Compiler+version: Visual studio 15.4
@horenmar
Copy link
Member

This is actually an intended change, called out in the "breaking changes" part of the v2.0.1 release.

We removed default up-scaling of epsilon (the relative margin allowed) because it silently gave bad results for lowish numbers: ie, it accepted the above comparison even though -0.001 and 0.0 are not within 10% of each other.

@horenmar horenmar added Resolved - pending review Issue waiting for feedback from the original author Working as intended labels Nov 13, 2017
@hoisunng
Copy link

hoisunng commented Dec 4, 2017

In my test cases I sometimes even have the case that 1e-20 != Approx(0).
So after this change, what is the suggested way of writing in Catch2, if we want to assert that something is approximately zero?

@horenmar
Copy link
Member

horenmar commented Dec 5, 2017

Depends on how close to zero you want to be, but for comparisons close to zero the recommended way is
value == Approx(0).margin(allowable_margin).

@horenmar horenmar removed the Resolved - pending review Issue waiting for feedback from the original author label Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants