'How to override BOOST_TEST with an absolute tolerance

I have data with a small dynamic range, and a moderate level of fuzziness (atomic coordinates). I'd like to write tests that check that two coordinates are pretty much equal:

BOOST_AUTO_TEST_CASE(two_routes, * boost::unit_test::tolerance(0.002))
{
    auto mol = get_a_mol();
    auto x1 = route1(mol);
    auto x2 = route2(mol);

    BOOST_TEST(x1 == x2);
}

This works well for most coordinates, but when my returned values are near zero, I get silly things like:

check 0.001 == 0.002 has failed [0.001 != 0.002]: relative difference exceeds tolerance [1 > 0.002]

What's the idiomatic way to handle this in the boost test framework? I've been trying to use boost::math::fpc::close_at_tolerance() to no avail.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source