Torri, Stephen CIV NSWCDD, W15
From: boost-users-bounces <at> lists.boost.org on behalf of Gennadiy Rozental Sent: Thu 9/9/2010 8:33 PM To: boost-users <at> lists.boost.org Subject: Re: [Boost-users][Boost.Test] Understanding the correct use of
BOOST_CHECK_CLOSE and >BOOST_CHECK_CLOSE_FRACTION
Use BOOST_CHECK_SMALL( a-b, tolerance ).
That said I really recommend you to use assertions based on relative errors, since they give more reliable results.
Thanks for the input. On the advice of a co-worker I am using a normalized variance ( value - reference ) / reference. Of course you can't use the check if the reference is zero. In that case I simply use BOOST_CHECK_EQUAL. Here is how I did the macro:
#define BOOST_CHECK_VARIANCE( L, R ) BOOST_CHECK_LT ( fabs ( ( L - R ) / R ), 1e-9 )
This is pretty much what BOOST_CHECK_CLOSE_FRACTION is doing, but it's more precise. It checks: (L-R)/R < T && (L-R)/L < T
I can change that to be
#define BOOST_CHECK_VARIANCE( L, R ) BOOST_CHECK_SMALL ( ( L - R ) / R, 1e-9 )
What would have to do finish the implementation of a proper print algorithm so
Just use BOOST_CHECK_CLOSE_FRACTION if you ask me. that 9.999999e-13 is
displayed as 1e-12?
One need to implement this algorithm: http://tinyurl.com/28du8d4 Gennadiy