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

Test fails when it should pass for certain real numbers #37

Closed
samaursa opened this issue Jun 4, 2011 · 5 comments
Closed

Test fails when it should pass for certain real numbers #37

samaursa opened this issue Jun 4, 2011 · 5 comments

Comments

@samaursa
Copy link
Contributor

samaursa commented Jun 4, 2011

REQUIRE(atan2(-862.42, 78.5149) == -1.480006);

The above code fails, with the output:

atan2(-862.42, 78.5149) == -1.48001 failed for: -1.48001 == -1.48001

I am not sure why, considering they are equal. I initially tried it with Approx, but the result was the same.

@samaursa
Copy link
Contributor Author

samaursa commented Jun 4, 2011

My mistake, the Approx strictness was higher than I expected.

@samaursa samaursa closed this as completed Jun 4, 2011
@philsquared
Copy link
Collaborator

You can set the tolerance level (epsilon) for each Approx call by using the syntax:
Approx( x ).epsilon( y );

I'll soon be adding the ability to specify epsilons for a range of Approx's (or all of them).

Make sure you have the latest Catch (as of last friday/ IIRC) because I did change Approx to be slightly less strict (now 100x epsilon for float)

@philsquared
Copy link
Collaborator

In fact I've just pushed up another commit for this.
You can now create your own Approx instance with settings for epsilon and scale.
See the last test case in https://github.com/philsquared/Catch/blob/master/projects/SelfTest/ApproxTests.cpp for an example.

Approx is a class, and usually when you use it you construct a single, temporary, instance on the fly.
But now you can create a named instance with epsilon and scale values that can be reused.
You can create this instance locally to your test case, or globally to your test app, if you like.

@samaursa
Copy link
Contributor Author

samaursa commented Dec 3, 2011

Sorry, I should have acknowledged your commit. It works very well, thanks.

@philsquared
Copy link
Collaborator

Thanks for letting me know, @samaursa (eventually ;-) )

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