Can anyone describe the difference in behavior between BOOST_CHECK_CLOSE and BOOST_CHECK_CLOSE_FRACTION? The documentation implies the that both m
@Gennadiy: Zero can be close to any small value. :-) Relative differences grow arbitrarily large if the expected value is very close to zero.
Here is a workaround function I use to unit-test double values: if the expected value is very small or zero then I check the smallness of the observed value, otherwise I check closeness:
void dbl_check_close(
double expected, double observed,
double small, double pct_tol
) {
if (std::fabs(expected) < small) {
BOOST_CHECK_SMALL(observed, small);
} else {
BOOST_CHECK_CLOSE(expected, observed, pct_tol);
}
}
Of course it would be great to have a BOOST_CHECK_SMALL_OR_CLOSE macro that does this automatically. Gennadiy could perhaps talk to the author of Boost.Test ;-)