]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/include/boost/test/tools/detail/tolerance_manip.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / test / include / boost / test / tools / detail / tolerance_manip.hpp
1 // (C) Copyright Gennadiy Rozental 2001.
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 //! @file
9 //! @brief Floating point comparison tolerance manipulators
10 //!
11 //! This file defines several manipulators for floating point comparison. These
12 //! manipulators are intended to be used with BOOST_TEST.
13 // ***************************************************************************
14
15 #ifndef BOOST_TEST_TOOLS_DETAIL_TOLERANCE_MANIP_HPP_012705GER
16 #define BOOST_TEST_TOOLS_DETAIL_TOLERANCE_MANIP_HPP_012705GER
17
18 // Boost Test
19 #include <boost/test/tools/detail/fwd.hpp>
20 #include <boost/test/tools/detail/indirections.hpp>
21
22 #include <boost/test/tools/fpc_tolerance.hpp>
23 #include <boost/test/tools/floating_point_comparison.hpp>
24
25 #include <boost/test/detail/suppress_warnings.hpp>
26
27 //____________________________________________________________________________//
28
29 namespace boost {
30 namespace test_tools {
31 namespace tt_detail {
32
33 // ************************************************************************** //
34 // ************** fpc tolerance manipulator ************** //
35 // ************************************************************************** //
36
37 template<typename FPT>
38 struct tolerance_manip {
39 explicit tolerance_manip( FPT const & tol ) : m_value( tol ) {}
40
41 FPT m_value;
42 };
43
44 //____________________________________________________________________________//
45
46 struct tolerance_manip_delay {};
47
48 template<typename FPT>
49 inline tolerance_manip<FPT>
50 operator%( FPT v, tolerance_manip_delay const& )
51 {
52 BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based<FPT>::value),
53 "tolerance should be specified using a floating points type" );
54
55 return tolerance_manip<FPT>( FPT(v / 100) );
56 }
57
58 //____________________________________________________________________________//
59
60 template<typename E, typename FPT>
61 inline assertion_result
62 operator<<(assertion_evaluate_t<E> const& ae, tolerance_manip<FPT> const& tol)
63 {
64 local_fpc_tolerance<FPT> lt( tol.m_value );
65
66 return ae.m_e.evaluate();
67 }
68
69 //____________________________________________________________________________//
70
71 template<typename FPT>
72 inline int
73 operator<<( unit_test::lazy_ostream const&, tolerance_manip<FPT> const& ) { return 0; }
74
75 //____________________________________________________________________________//
76
77 template<typename FPT>
78 inline check_type
79 operator<<( assertion_type const& /*at*/, tolerance_manip<FPT> const& ) { return CHECK_BUILT_ASSERTION; }
80
81 //____________________________________________________________________________//
82
83 } // namespace tt_detail
84
85
86 /*! Tolerance manipulator
87 *
88 * These functions return a manipulator that can be used in conjunction with BOOST_TEST
89 * in order to specify the tolerance with which floating point comparisons are made.
90 */
91 template<typename FPT>
92 inline tt_detail::tolerance_manip<FPT>
93 tolerance( FPT v )
94 {
95 BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based<FPT>::value),
96 "tolerance only for floating points" );
97
98 return tt_detail::tolerance_manip<FPT>( v );
99 }
100
101 //____________________________________________________________________________//
102
103 //! @overload tolerance( FPT v )
104 template<typename FPT>
105 inline tt_detail::tolerance_manip<FPT>
106 tolerance( fpc::percent_tolerance_t<FPT> v )
107 {
108 BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based<FPT>::value),
109 "tolerance only for floating points" );
110
111 return tt_detail::tolerance_manip<FPT>( static_cast<FPT>(v.m_value / 100) );
112 }
113
114 //____________________________________________________________________________//
115
116 //! @overload tolerance( FPT v )
117 inline tt_detail::tolerance_manip_delay
118 tolerance()
119 {
120 return tt_detail::tolerance_manip_delay();
121 }
122
123 //____________________________________________________________________________//
124
125 } // namespace test_tools
126 } // namespace boost
127
128 #include <boost/test/detail/enable_warnings.hpp>
129
130 #endif // BOOST_TEST_TOOLS_DETAIL_TOLERANCE_MANIP_HPP_012705GER