unit test BOOST_CHECK_CLOSE absolute
I am doing unit tests using boost utf but I have sometimes problems with BOOST_CHECK_SMALL because it checks relative value. For example, I am comparing coordinates in 2d spaces and the relative value is not important, the meaningfull value is the absolute difference between coordinates. I have seen that I can do a BOOST_CHECK_SMALL(fabs(x - expected_x), 1e-3); but in this can I don't have a good message when the test fails (it does not show the value of x and the expected_x). In fact I would like to have something like BOOST_CHECK_CLOSE_ABSOLUTE ? Is there something equivalent or how can I do something like this ?
Renaud Lepère
I am doing unit tests using boost utf but I have sometimes problems with BOOST_CHECK_SMALL because it checks relative value.
BOOST_CHECK_SMALL checks for absolute value, but you probably meant BOOST_CHECK_CLOSE.
For example, I am comparing coordinates in 2d spaces and the relative value is not important, the meaningfull value is the absolute difference between coordinates.
It is almost never true. Related error gives you much better estimate of closeness.
I have seen that I can do a BOOST_CHECK_SMALL(fabs(x - expected_x), 1e-3);
but in this can I don't have a good message when the test fails (it does not show the value of x and the expected_x).
In fact I would like to have something like BOOST_CHECK_CLOSE_ABSOLUTE ? Is there something equivalent or how can I do something like this ?
Don't. Specify relative tolerance (or percent tolerance) and keep using BOOST_CHECK_CLOSE. Gennadiy
-----Original Message----- From: Boost-users [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Renaud Lepère Sent: 10 January 2015 13:10 To: boost-users@lists.boost.org Subject: [Boost-users] unit test BOOST_CHECK_CLOSE absolute
I am doing unit tests using boost utf but I have sometimes problems with BOOST_CHECK_SMALL because it checks relative value.
For example, I am comparing coordinates in 2d spaces and the relative value is not important, the meaningfull value is the absolute difference between coordinates.
I have seen that I can do a BOOST_CHECK_SMALL(fabs(x - expected_x), 1e-3);
but in this can I don't have a good message when the test fails (it does not show the value of x and the expected_x).
In fact I would like to have something like BOOST_CHECK_CLOSE_ABSOLUTE ? Is there something equivalent or how can I do something like this ?
FWIW I've also wanted the *values* in a message (rather than just a test fail). (But that's separate from the relative v absolute distinction). Paul
participants (3)
-
Gennadiy Rozental
-
Paul A. Bristow
-
Renaud Lepère