Boost logo

Boost :

From: Ullrich Koethe (u.koethe_at_[hidden])
Date: 2001-12-06 12:32:58


Fernando Cacciola wrote:
>
> I'm not saying that we shouldn't provide a facility to test floating point
> and collection equality.
> I'm not saying neither that the Unit Test Library distribution shouldn't
> come with these facilities until they are factored out.
> What I'm saying is that I prefer these facilities being decoupled.
>
> Specifically:
>
> Currently we have:
>
> #define BOOST_CHECK_CLOSE(left, right, tolerance_or_number)
> #define BOOST_CHECK_WEAK_CLOSE(left, right, tolerance_or_number)
>
> The test is too much embebbed in the test framework.
> What if I need a different comparison scheme.
> What if the comparison scheme I need is so different that even the 3rd
> argument is irrelevant or not enough.
>
> What I suggest is to provide something like:
>
> template<class T> bool fp_equal(T const& l,T const& r) ;
> template<class T> bool fp_equal2(T const& l,T const& r, T const& tol) ;
> template<class T> bool fp_equal32(T const& l,T const& r, T const& tol) ;
>

Are you suggesting to write:

    BOOST_CHECK(fp_equal2(left, right, 1.0e-7));

instead of

    BOOST_CHECK_CLOSE(left, right, 1.0e-7);

This would be possible (in fact, it already is, provided you implement
the fp_equal templates). But the first version doesn't produce as good
an error message because the message cannot contain the numbers being
compared. In my opinion, we don't understand the limitations of the
current scheme enough to come up with the optimial solution right now.
So I'd prefer to wait with refactoring until we have more experience
with the new framework.
   
> > [As an aside: it would be really helpful for testing if there were some
> > support for determining the right tolerance for floating point
> > comparisons automatically on every platform, depending on the expected
> > error of the computation. Would this be part of your module?]
> >
> AFAIK, there isn't any really right tolerance.
> It always depends on the input and the sequence of operations besides the
> platform and required error bound.
> The best think we -as library providers- can do is to provide a set of
> different schemes, some with fixed epsilon-based tolerances and with user
> provided tolerances, properly documented. Users would have to choose the
> right one.

Yes, its difficult. But I'd like to have something in between fixed
epsilons and user provided tolerances. Often, it is unclear whether
1.e-5 is still acceptable or already an error. So, the system might
provide functions to roughly estimate the expected error on the basis of
the nature of the computation, the orders of magnitude of the numbers
involved, and the properties of the current platform.

Ulli

-- 
 ________________________________________________________________
|                                                                |
| Ullrich Koethe  Universität Hamburg / University of Hamburg    |
|                 FB Informatik / Dept. of Computer Science      |
|                 AB Kognitive Systeme / Cognitive Systems Group |
|                                                                |
| Phone: +49 (0)40 42883-2573                Vogt-Koelln-Str. 30 |
| Fax:   +49 (0)40 42883-2572                D - 22527 Hamburg   |
| Email: u.koethe_at_[hidden]               Germany             |
|        koethe_at_[hidden]                        |
| WWW:   http://kogs-www.informatik.uni-hamburg.de/~koethe/      |
|________________________________________________________________|

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