Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:09:52

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 //! @file
0009 //! @brief Floating point comparison tolerance manipulators
0010 //! 
0011 //! This file defines several manipulators for floating point comparison. These
0012 //! manipulators are intended to be used with BOOST_TEST.
0013 // ***************************************************************************
0014 
0015 #ifndef BOOST_TEST_TOOLS_DETAIL_TOLERANCE_MANIP_HPP_012705GER
0016 #define BOOST_TEST_TOOLS_DETAIL_TOLERANCE_MANIP_HPP_012705GER
0017 
0018 // Boost Test
0019 #include <boost/test/tools/detail/fwd.hpp>
0020 #include <boost/test/tools/detail/indirections.hpp>
0021 
0022 #include <boost/test/utils/lazy_ostream.hpp>
0023 #include <boost/test/tools/fpc_tolerance.hpp>
0024 #include <boost/test/tools/floating_point_comparison.hpp>
0025 
0026 #include <ostream>
0027 
0028 #include <boost/test/detail/suppress_warnings.hpp>
0029 
0030 //____________________________________________________________________________//
0031 
0032 namespace boost {
0033 namespace test_tools {
0034 namespace tt_detail {
0035 
0036 // ************************************************************************** //
0037 // **************           fpc tolerance manipulator          ************** //
0038 // ************************************************************************** //
0039 
0040 //! Tolerance manipulator, not to be used directly
0041 //! This is not a terminal of the expression
0042 template<typename FPT>
0043 struct tolerance_manip {
0044     explicit tolerance_manip( FPT const & tol ) : m_value( tol ) {}
0045 
0046     FPT m_value;
0047 };
0048 
0049 //____________________________________________________________________________//
0050 
0051 struct tolerance_manip_delay {};
0052 
0053 template<typename FPT>
0054 inline tolerance_manip<FPT>
0055 operator%( FPT v, tolerance_manip_delay const& )
0056 {
0057     BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based<FPT>::value), 
0058                              "tolerance should be specified using a floating points type" );
0059 
0060     return tolerance_manip<FPT>( FPT(v / 100) );
0061 }
0062 
0063 template <typename FPT>
0064 struct tolerance_evaluation_context: assertion_evaluation_context {
0065     tolerance_evaluation_context(FPT tol)
0066     : assertion_evaluation_context( true ) // has report
0067     , m_tolerance_context(tol)
0068     {}
0069 
0070     local_fpc_tolerance<FPT> m_tolerance_context;
0071 };
0072 
0073 //____________________________________________________________________________//
0074 
0075 template<typename E, typename FPT>
0076 inline assertion_evaluate_t<E>
0077 operator<<(assertion_evaluate_t<E> const& ae, tolerance_manip<FPT> const& tol)
0078 {
0079     return ae.stack_context(
0080       typename assertion_evaluate_t<E>::context_holder(
0081         new tolerance_evaluation_context<FPT>( tol.m_value ))
0082     );
0083 }
0084 
0085 //____________________________________________________________________________//
0086 
0087 template<typename FPT>
0088 unit_test::lazy_ostream &
0089 operator<<( unit_test::lazy_ostream &o, tolerance_manip<FPT> const& )   { return o; }
0090 
0091 // needed for the lazy evaluation in lazy_ostream as for commutativity with other arguments
0092 template<typename FPT>
0093 std::ostream& 
0094 operator<<( std::ostream& o, tolerance_manip<FPT> const& )              { return o; }
0095 
0096 
0097 //____________________________________________________________________________//
0098 
0099 template<typename FPT>
0100 inline assertion_type
0101 operator<<( assertion_type const& /*at*/, tolerance_manip<FPT> const& ) {
0102     return assertion_type(CHECK_BUILT_ASSERTION); 
0103 }
0104 
0105 //____________________________________________________________________________//
0106 
0107 } // namespace tt_detail
0108 
0109 
0110 /*! Tolerance manipulator
0111  *
0112  * These functions return a manipulator that can be used in conjunction with BOOST_TEST
0113  * in order to specify the tolerance with which floating point comparisons are made.
0114  */
0115 template<typename FPT>
0116 inline tt_detail::tolerance_manip<FPT>
0117 tolerance( FPT v )
0118 {
0119     BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based<FPT>::value), 
0120                              "tolerance only for floating points" );
0121 
0122     return tt_detail::tolerance_manip<FPT>( v );
0123 }
0124 
0125 //____________________________________________________________________________//
0126 
0127 //! @overload tolerance( FPT v )
0128 template<typename FPT>
0129 inline tt_detail::tolerance_manip<FPT>
0130 tolerance( fpc::percent_tolerance_t<FPT> v )
0131 {
0132     BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based<FPT>::value), 
0133                              "tolerance only for floating points" );
0134 
0135     return tt_detail::tolerance_manip<FPT>( static_cast<FPT>(v.m_value / 100) );
0136 }
0137 
0138 //____________________________________________________________________________//
0139 
0140 //! @overload tolerance( FPT v )
0141 inline tt_detail::tolerance_manip_delay
0142 tolerance()
0143 {
0144     return tt_detail::tolerance_manip_delay();
0145 }
0146 
0147 //____________________________________________________________________________//
0148 
0149 } // namespace test_tools
0150 } // namespace boost
0151 
0152 #include <boost/test/detail/enable_warnings.hpp>
0153 
0154 #endif // BOOST_TEST_TOOLS_DETAIL_TOLERANCE_MANIP_HPP_012705GER