tolerance_03.run-fail.cpp 937 B

1234567891011121314151617181920212223242526272829303132
  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. // See http://www.boost.org/libs/test for the library home page.
  6. //[example_code
  7. #define BOOST_TEST_MODULE tolerance_03
  8. #include <boost/test/included/unit_test.hpp>
  9. namespace utf = boost::unit_test;
  10. double x = 10.000000;
  11. double d = 0.000001;
  12. BOOST_AUTO_TEST_CASE(passing, * utf::tolerance(0.0001))
  13. {
  14. BOOST_TEST(x == x + d); // equal with tolerance
  15. BOOST_TEST(x >= x + d); // ==> greater-or-equal
  16. BOOST_TEST(d == .0); // small with tolerance
  17. }
  18. BOOST_AUTO_TEST_CASE(failing, * utf::tolerance(0.0001))
  19. {
  20. BOOST_TEST(x - d < x); // less, but still too close
  21. BOOST_TEST(x - d != x); // unequal but too close
  22. BOOST_TEST(d > .0); // positive, but too small
  23. BOOST_TEST(d < .0); // not sufficiently negative
  24. }
  25. //]