]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/units/test/test_close.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / units / test / test_close.hpp
1 /*
2 Copyright 2021 Glen Joseph Fernandes
3 (glenjofe@gmail.com)
4
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
7 */
8 #ifndef BOOST_UNITS_TEST_CLOSE_HPP
9 #define BOOST_UNITS_TEST_CLOSE_HPP
10
11 #include <boost/core/lightweight_test.hpp>
12 #include <algorithm>
13 #include <limits>
14 #include <cmath>
15
16 /*
17 Provide a predicate for BOOST_TEST_WITH that is equivalent to
18 what was provided by the previous test framework.
19 */
20 class close_to {
21 public:
22 explicit close_to(double f)
23 : f_(f) { }
24
25 bool operator()(double l, double r) const {
26 return std::abs(l - r) <=
27 (std::max)(f_ * (std::max)(std::abs(l), std::abs(r)), 0.);
28 }
29
30 private:
31 double f_;
32 };
33
34 #define BOOST_UNITS_TEST_CLOSE(l,r,f) BOOST_TEST_WITH((l),(r),close_to((f)))
35
36 #endif