Boost logo

Boost Users :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2007-05-31 22:10:56


"Chris Fairles" <chris.fairles_at_[hidden]> wrote in message
news:fac6bb500705311219s4a447924p26dd6d5d8945793c_at_mail.gmail.com...
> Thanks for the suggestion, tried a few things. I have
> #define CHECK_IS_CLOSE_WEAK(x, y, t) \
> boost::test_tools::check_is_close((x),(y),
> boost::test_tools::percent_tolerance(t), boost::test_tools::FPC_WEAK)
>
> which works fine with when either x or y is 0. I tried the predicate
> method, something like:

This is wrong. check_is_close can't return true if either x or y is zero
regardless of weak/strong flag. Relative errors are 1 and Inf. Both are more
than 1e-05

> BOOST_CHECK_PREDICATE(boost::test_tools::check_is_close,
> (first)(second)(boost::test_tools::percent_tolerance( e
> ))(boost::test_tools::FPC_WEAK))
>
> But this fails
> check boost::test_tools::check_is_close( m_cmp(i,j), m(i,j),
> boost::test_tools::percent_tolerance( tolerance ),
> boost::test_tools::FPC_WEAK ) failed for ( 0, -2.2204460492503131e-16,
> 1e-05, 1 )

As expected.

> Am I not using the predicate correctly?

You should use differerent predicate, which uses check_is_close in regular
cases and check_is_small in case if either of the arguments is zero. It's
still not exactly correct, since in general you can't use the same tolerance
for both comparizons: one is relative, another is absolute.

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