1 // Copyright (c) 2015 Boost.Test team 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 // See http://www.boost.org/libs/test for the library home page. 7 8 //[example_code 9 #define BOOST_TEST_MODULE tolerance_03 10 #include <boost/test/included/unit_test.hpp> 11 namespace utf = boost::unit_test; 12 13 double x = 10.000000; 14 double d = 0.000001; 15 16 BOOST_AUTO_TEST_CASE(passing, * utf::tolerance(0.0001)) 17 { 18 BOOST_TEST(x == x + d); // equal with tolerance 19 BOOST_TEST(x >= x + d); // ==> greater-or-equal 20 21 BOOST_TEST(d == .0); // small with tolerance 22 } 23 24 BOOST_AUTO_TEST_CASE(failing, * utf::tolerance(0.0001)) 25 { 26 BOOST_TEST(x - d < x); // less, but still too close 27 BOOST_TEST(x - d != x); // unequal but too close 28 29 BOOST_TEST(d > .0); // positive, but too small 30 BOOST_TEST(d < .0); // not sufficiently negative 31 } 32 //] 33