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

Compare collections of floating point values with tolerance #173

Closed
Flamefire opened this issue Oct 19, 2018 · 6 comments
Closed

Compare collections of floating point values with tolerance #173

Flamefire opened this issue Oct 19, 2018 · 6 comments
Assignees
Milestone

Comments

@Flamefire
Copy link
Contributor

Currently you can use either:

  • BOOST_TEST_REQUIRE( output == outputDesired, boost::test_tools::per_element() );
  • BOOST_TEST_REQUIRE( output == outputDesired, boost::test_tools::tolerance( 1e-12f ) );

But you cannot use both.

What is the preferred way to compare collections (e.g. vectors) of floating point values?

This is a common use case for testing numeric algorithms: Check results of optimized version vs. naive implementation.

@raffienficiaud
Copy link
Member

@raffienficiaud raffienficiaud self-assigned this Nov 11, 2018
@Flamefire
Copy link
Contributor Author

This is our current work-around but limits the abilities. Imagine a test where you test matrix operations and first have to assert that some intermediate value (e.g. input, transposed matrix, ...) is exactly equal and then test the result of some calculation. Yes those can be put into separate unit tests, but maybe they are so closely related that one does not want to do this.

@raffienficiaud raffienficiaud added this to the 1.72 milestone Nov 3, 2019
@raffienficiaud raffienficiaud added 1.73 and removed 1.72 labels Dec 4, 2019
@raffienficiaud raffienficiaud modified the milestones: 1.72, 1.73 Dec 4, 2019
@raffienficiaud
Copy link
Member

@Flamefire there is a WIP branch for this: topic/PR-187-BOOST_TEST-with-tolerance-message: it would be nice if you can give a try until I polish it up. It should address this particular issue together with #242 and #187.

I'll try to make that for 1.73.

@raffienficiaud
Copy link
Member

Merged to master.

@Char-Aznable
Copy link

@raffienficiaud I struggle to find documentation on the OP's proposal. What exactly is the solution to this problem that get merged?

@raffienficiaud
Copy link
Member

@Char-Aznable sorry for the late answer: now it is possible to combine both boost::test_tools::per_element() and boost::test_tools::tolerance( 1e-12f ). The documentation is only in the change log of 1.73.

If we need more, let me know I'll open a ticket.

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