Subject: Re: [boost] boost-test, why is there no DOUBLES_EQUAL?
From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2011-04-08 05:12:05
Sebastian Nowozin <nowozin <at> gmail.com> writes:
> This does not do the job, as
> BOOST_CHECK_SMALL(std::fabs(first - second), 1.0e-3)
> will be about as useful as
> BOOST_CHECK(std::fabs(first - second) <= 1.0e-3)
> It is not useful because in case this check fails I do not get to see
> the original values of both 'first' and 'second', but only their
That's what you get for using suboptimal testing approach ;)
> In my application, first and second are in the range of 0 to 1, but
> can in fact be quite close to zero.
You can still use ratio or percent based comparisons. They are more stable in
general case and unless you have a very strong reason to prefer absolute
comparison you should use relative one.
> The qualitative test is correct
> if the absolute difference between first and second is small enough,
> irrespectively of the absolute value of first. Therefore, I fail to
> see why the boost test library provides only BOOST_CHECK_CLOSE and
> BOOST_CHECK_SMALL, but no analog to CPPUNIT_ASSERT_DOUBLES_EQUAL.
You are free to implement your own macro/comparison functor, but there are known
good practices and Boost.Test punishes you a bit for not following them.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk