// (C) Copyright Gennadiy Rozental 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org/libs/test for the library home page. // //! @file //! @brief Floating point comparison tolerance manipulators //! //! This file defines several manipulators for floating point comparison. These //! manipulators are intended to be used with BOOST_TEST. // *************************************************************************** #ifndef BOOST_TEST_TOOLS_DETAIL_TOLERANCE_MANIP_HPP_012705GER #define BOOST_TEST_TOOLS_DETAIL_TOLERANCE_MANIP_HPP_012705GER // Boost Test #include #include #include #include #include #include #include //____________________________________________________________________________// namespace boost { namespace test_tools { namespace tt_detail { // ************************************************************************** // // ************** fpc tolerance manipulator ************** // // ************************************************************************** // //! Tolerance manipulator, not to be used directly //! This is not a terminal of the expression template struct tolerance_manip { explicit tolerance_manip( FPT const & tol ) : m_value( tol ) {} FPT m_value; }; //____________________________________________________________________________// struct tolerance_manip_delay {}; template inline tolerance_manip operator%( FPT v, tolerance_manip_delay const& ) { BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based::value), "tolerance should be specified using a floating points type" ); return tolerance_manip( FPT(v / 100) ); } template struct tolerance_evaluation_context: assertion_evaluation_context { tolerance_evaluation_context(FPT tol) : assertion_evaluation_context( true ) // has report , m_tolerance_context(tol) {} local_fpc_tolerance m_tolerance_context; }; //____________________________________________________________________________// template inline assertion_evaluate_t operator<<(assertion_evaluate_t const& ae, tolerance_manip const& tol) { return ae.stack_context( typename assertion_evaluate_t::context_holder( new tolerance_evaluation_context( tol.m_value )) ); } //____________________________________________________________________________// template unit_test::lazy_ostream & operator<<( unit_test::lazy_ostream &o, tolerance_manip const& ) { return o; } // needed for the lazy evaluation in lazy_ostream as for commutativity with other arguments template std::ostream& operator<<( std::ostream& o, tolerance_manip const& ) { return o; } //____________________________________________________________________________// template inline assertion_type operator<<( assertion_type const& /*at*/, tolerance_manip const& ) { return assertion_type(CHECK_BUILT_ASSERTION); } //____________________________________________________________________________// } // namespace tt_detail /*! Tolerance manipulator * * These functions return a manipulator that can be used in conjunction with BOOST_TEST * in order to specify the tolerance with which floating point comparisons are made. */ template inline tt_detail::tolerance_manip tolerance( FPT v ) { BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based::value), "tolerance only for floating points" ); return tt_detail::tolerance_manip( v ); } //____________________________________________________________________________// //! @overload tolerance( FPT v ) template inline tt_detail::tolerance_manip tolerance( fpc::percent_tolerance_t v ) { BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based::value), "tolerance only for floating points" ); return tt_detail::tolerance_manip( static_cast(v.m_value / 100) ); } //____________________________________________________________________________// //! @overload tolerance( FPT v ) inline tt_detail::tolerance_manip_delay tolerance() { return tt_detail::tolerance_manip_delay(); } //____________________________________________________________________________// } // namespace test_tools } // namespace boost #include #endif // BOOST_TEST_TOOLS_DETAIL_TOLERANCE_MANIP_HPP_012705GER