• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Negative test for BOOST_TEST_WITH
2 //
3 // Copyright 2020 Bjorn Reese
4 // Copyright 2020 Peter Dimov
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // https://www.boost.org/LICENSE_1_0.txt
8 
9 #include <boost/core/lightweight_test.hpp>
10 #include <cmath>
11 
12 template <typename T>
13 struct with_tolerance
14 {
with_tolerancewith_tolerance15     with_tolerance( T tolerance ): tolerance( tolerance )
16     {
17     }
18 
operator ()with_tolerance19     bool operator()( T lhs, T rhs ) const
20     {
21         return std::abs( lhs - rhs ) <= tolerance;
22     }
23 
24 private:
25 
26     T tolerance;
27 };
28 
test_tolerance_predicate()29 void test_tolerance_predicate()
30 {
31     BOOST_TEST_WITH( 1.0, 1.0 - 1e-6, with_tolerance<double>(1e-7) );
32     BOOST_TEST_WITH( 1.0, 1.0 + 1e-6, with_tolerance<double>(1e-7) );
33 }
34 
main()35 int main()
36 {
37     test_tolerance_predicate();
38     return boost::report_errors() == 2;
39 }
40