Boost logo

Boost :

Subject: Re: [boost] boost-test, why is there no DOUBLES_EQUAL?
From: Thomas Klimpel (Thomas.Klimpel_at_[hidden])
Date: 2011-04-11 14:01:08


Gennadiy Rozental wrote:
> Jeffrey Lee Hellrung, Jr. writes:
>
> > Perhaps, but that makes an implicit assumption about the "usual"
> > application.
>
>
> I used word usually only because I prefer never or rarely use
> absolute statements.

So you don't like absolute comparisons and rarely use absolute statements. Sounds very consistent to me.

> > In any case, usual or not, do we accept that absolute
> > tolerances are sometimes preferable to relative tolerances?
> > I would.
>
> I would not.

OK, but do we accept that relative tolerances in the strict sense are sometimes not appropriate?

> In my experience I've never seen a necessity for one
> (excluding the case where you want to check if something is small and
> in this case BOOST_CHECK_SMALL is strait to the point).

So you indeed accept that relative tolerances are sometimes not the way to go.

However, the cases where I had to use BOOST_CHECK_SMALL in the past are not well characterized by saying that I wanted to check something is small. I had a vector as the result of some matrix problem, and wanted to check that the difference to the correct solution vector in the 2-norm was smaller than a tolerance times the condition number of the problem times the 2-norm of the input data.

> I'd say that
> *usually* ;) desire to use absolute tolerance just indicates either
> lack of knowledge or lack of foresight. Even if you can come up with
> proper tolerance today, what will happen tomorrow when you change the
> notional or apply the same test in some other unrelated domain? With
> fraction based tolerance you can be much more comfortable that your
> test is still valid.

But BOOST_CHECK_CLOSE is often not the right way either. The problem is that BOOST_CHECK_CLOSE checks relative to the actual value, and not relative to the actual context. BOOST_CHECK_SMALL is fine for these cases, as far as the actual check is concerned. However, the resulting messages in case the check fails are suboptimal, as has been pointed out in this thread. But let me also point out that using BOOST_CHECK_DIFF_SMALL (absolute tolerance) on each component of a vector (similar to the use case described above) would produce much worse messages, because a single failed test would result in a flood of messages about failed checks. But using just BOOST_CHECK with an appropriate message seems to be a good solution.

> > absolute tolerances; do we not trust users enough to determine on
> > their own which tolerance type is appropriate for their application?
>
> Yes. That one of the concerns on my part.

Not very convincing, but also not completely wrong.

> In addition one you have
> two ways to do the same thing you'll have never ending stream of
> questions: what should one use?

Yes, should I use BOOST_CHECK_SMALL as I currently do for my described use case, or BOOST_CHECK with an appropriate error message?

Regards,
Thomas


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk