1//
2// Test for BOOST_TEST_WITH
3//
4// Copyright (c) 2020 Bjorn Reese
5//
6// Distributed under the Boost Software License, Version 1.0.
7// See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt
9//
10
11#include <boost/core/lightweight_test.hpp>
12#include <cmath>
13
14template <typename T>
15struct with_tolerance
16{
17 with_tolerance(T tolerance) : tolerance(tolerance) {}
18 bool operator()(T lhs, T rhs) const
19 {
20 return (std::abs(lhs - rhs) <= tolerance);
21 }
22
23private:
24 T tolerance;
25};
26
27void test_tolerance_predicate()
28{
29 BOOST_TEST_WITH( 1.0, 1.0, with_tolerance<double>(1e-5) );
30 BOOST_TEST_WITH( 1.0, 1.0 - 1e-6, with_tolerance<double>(1e-5) );
31 BOOST_TEST_WITH( 1.0, 1.0 + 1e-6, with_tolerance<double>(1e-5) );
32}
33
34int main()
35{
36 test_tolerance_predicate();
37
38 return boost::report_errors();
39}
40

source code of boost/libs/core/test/lightweight_test_with_test.cpp