Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Test] Understanding the correct use of BOOST_CHECK_CLOSE and BOOST_CHECK_CLOSE_FRACTION
From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2010-09-10 15:36:12


Torri, Stephen CIV NSWCDD, W15 <stephen.torri <at> navy.mil> writes:

>
> >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 )

Just use BOOST_CHECK_CLOSE_FRACTION if you ask me.
 
> What would have to do finish the implementation of a proper print algorithm so
that 9.999999e-13 is
> displayed as 1e-12?

One need to implement this algorithm:

http://tinyurl.com/28du8d4

Gennadiy


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net