mirror of
https://github.com/boostorg/test.git
synced 2026-01-28 19:52:10 +00:00
- macro indicating the availability of the variadic variant of BOOST_TEST
- replacing all boost::is_floating_point by a trait is_floating_point_comparable - reporting the errors messages in the static_asserts - compiling now the boost.mulitprecision test with C++03 and C++11 - adding the new API macros in the boost.mulitprecision test
This commit is contained in:
@@ -47,4 +47,8 @@
|
||||
# include <boost/test/tools/detail/tolerance_manip.hpp>
|
||||
#endif
|
||||
|
||||
#if !BOOST_PP_VARIADICS || ((__cplusplus >= 201103L) && BOOST_NO_CXX11_VARIADIC_MACROS)
|
||||
#define BOOST_TEST_NO_VARIADIC
|
||||
#endif
|
||||
|
||||
#endif // BOOST_TEST_TOOLS_HPP_111812GER
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <boost/utility/declval.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/type_traits/is_floating_point.hpp>
|
||||
|
||||
// STL
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
@@ -350,8 +349,8 @@ struct compare_fpv<op::NE<Lhs,Rhs>,FPT> {
|
||||
#define DEFINE_FPV_COMPARISON( oper, name, rev ) \
|
||||
template<typename Lhs,typename Rhs> \
|
||||
struct name<Lhs,Rhs,typename boost::enable_if_c< \
|
||||
is_floating_point<Lhs>::value && \
|
||||
is_floating_point<Rhs>::value>::type> { \
|
||||
(boost::math::fpc::traits::is_floating_point_comparable<Lhs>::value && \
|
||||
boost::math::fpc::traits::is_floating_point_comparable<Rhs>::value) >::type> { \
|
||||
typedef typename numeric::conversion_traits<Lhs,Rhs \
|
||||
>::supertype FPT; \
|
||||
typedef name<Lhs,Rhs> OP; \
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
#include <boost/test/tools/detail/indirections.hpp>
|
||||
|
||||
#include <boost/test/tools/fpc_tolerance.hpp>
|
||||
#include <boost/test/tools/floating_point_comparison.hpp>
|
||||
|
||||
|
||||
// Boost
|
||||
#include <boost/type_traits/is_floating_point.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
@@ -38,7 +38,7 @@ namespace tt_detail {
|
||||
|
||||
template<typename FPT>
|
||||
struct tolerance_manip {
|
||||
explicit tolerance_manip( FPT tol ) : m_value( tol ) {}
|
||||
explicit tolerance_manip( FPT const & tol ) : m_value( tol ) {}
|
||||
|
||||
FPT m_value;
|
||||
};
|
||||
@@ -51,9 +51,10 @@ template<typename FPT>
|
||||
inline tolerance_manip<FPT>
|
||||
operator%( FPT v, tolerance_manip_delay const& )
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_floating_point<FPT>::value );
|
||||
BOOST_STATIC_ASSERT_MSG( (boost::math::fpc::traits::is_floating_point_comparable<FPT>::value),
|
||||
"tolerance only for floating points" );
|
||||
|
||||
return tolerance_manip<FPT>( v * static_cast<FPT>(0.01) );
|
||||
return tolerance_manip<FPT>( static_cast<FPT>(v * 0.01) );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
@@ -87,7 +88,8 @@ template<typename FPT>
|
||||
inline tt_detail::tolerance_manip<FPT>
|
||||
tolerance( FPT v )
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_floating_point<FPT>::value );
|
||||
BOOST_STATIC_ASSERT_MSG( (boost::math::fpc::traits::is_floating_point_comparable<FPT>::value),
|
||||
"tolerance only for floating points" );
|
||||
|
||||
return tt_detail::tolerance_manip<FPT>( v );
|
||||
}
|
||||
@@ -98,9 +100,10 @@ template<typename FPT>
|
||||
inline tt_detail::tolerance_manip<FPT>
|
||||
tolerance( fpc::percent_tolerance_t<FPT> v )
|
||||
{
|
||||
BOOST_STATIC_ASSERT( is_floating_point<FPT>::value );
|
||||
BOOST_STATIC_ASSERT_MSG( (boost::math::fpc::traits::is_floating_point_comparable<FPT>::value),
|
||||
"tolerance only for floating points" );
|
||||
|
||||
return tt_detail::tolerance_manip<FPT>( v.m_value * static_cast<FPT>(0.01) );
|
||||
return tt_detail::tolerance_manip<FPT>( static_cast<FPT>(v.m_value * 0.01) );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <boost/numeric/conversion/conversion_traits.hpp> // for numeric::conversion_traits
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/type_traits/is_floating_point.hpp>
|
||||
|
||||
// STL
|
||||
#include <iosfwd>
|
||||
@@ -42,6 +43,14 @@ enum strength {
|
||||
FPC_WEAK // "Close enough" - equation 2' in docs.
|
||||
};
|
||||
|
||||
|
||||
namespace traits {
|
||||
template <class T>
|
||||
struct is_floating_point_comparable : boost::is_floating_point<T>::type
|
||||
{};
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** details ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
@@ -281,7 +281,7 @@ struct comp_supertype {
|
||||
// value of integral type is promoted to the floating. The same for float and double
|
||||
// But we don't want to compare two values of integral types using this tool.
|
||||
typedef typename numeric::conversion_traits<FPT1,FPT2>::supertype type;
|
||||
BOOST_STATIC_ASSERT( !is_integral<type>::value );
|
||||
BOOST_STATIC_ASSERT_MSG( !is_integral<type>::value, "Only floating-point types can be compared!");
|
||||
};
|
||||
|
||||
} // namespace tt_detail
|
||||
|
||||
@@ -133,7 +133,10 @@ test-suite "unit_test_framework_test"
|
||||
[ test-btl-lib run : test_dont_print_log_value : boost_unit_test_framework ]
|
||||
|
||||
# test for multiprecision / trac 11054
|
||||
[ test-btl-lib run : test_fp_multiprecision_close_fraction : boost_unit_test_framework ]
|
||||
[ test-btl-lib run : test_fp_multiprecision_close_fraction : boost_unit_test_framework : :
|
||||
test_fp_multiprecision_close_fraction.cpp ]
|
||||
[ test-btl-lib-c11 run : test_fp_multiprecision_close_fraction_new_api : boost_unit_test_framework : :
|
||||
test_fp_multiprecision_close_fraction.cpp ]
|
||||
;
|
||||
|
||||
test-suite "multithreaded_test"
|
||||
|
||||
@@ -14,16 +14,59 @@
|
||||
#define BOOST_TEST_MAIN
|
||||
#define BOOST_LIB_DIAGNOSTIC "on"// Show library file details.
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/floating_point_comparison.hpp> // Extra test tool for FP comparison.
|
||||
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
//[expression_template_1
|
||||
|
||||
#include <limits>
|
||||
#include <iostream>
|
||||
#include <boost/multiprecision/cpp_dec_float.hpp>
|
||||
|
||||
#include <boost/test/floating_point_comparison.hpp> // Extra test tool for FP comparison.
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
|
||||
typedef boost::multiprecision::number<
|
||||
boost::multiprecision::cpp_dec_float<50>,
|
||||
boost::multiprecision::et_off> cpp_dec_float_50_noet;
|
||||
|
||||
typedef boost::multiprecision::number<
|
||||
boost::multiprecision::cpp_dec_float<50>,
|
||||
boost::multiprecision::et_on> cpp_dec_float_50_et;
|
||||
|
||||
|
||||
namespace boost { namespace math { namespace fpc { namespace traits {
|
||||
|
||||
//template <>
|
||||
//struct is_floating_point_comparable< cpp_dec_float_50_noet > : boost::mpl::true_ {};
|
||||
|
||||
//template <>
|
||||
//struct is_floating_point_comparable< cpp_dec_float_50_et > : boost::mpl::true_ {};
|
||||
|
||||
|
||||
template <class A, boost::multiprecision::expression_template_option B>
|
||||
struct is_floating_point_comparable< boost::multiprecision::number<
|
||||
A,
|
||||
B > > : boost::mpl::true_ {};
|
||||
|
||||
/* template <class A, bool B>
|
||||
struct is_floating_point_comparable< boost::multiprecision::number<
|
||||
A,
|
||||
B > > : boost::mpl::true_ {};
|
||||
*/
|
||||
|
||||
template <class tag, class Arg1, class Arg2, class Arg3, class Arg4>
|
||||
struct is_floating_point_comparable<
|
||||
boost::multiprecision::detail::expression<
|
||||
tag, Arg1, Arg2, Arg3, Arg4> > : boost::mpl::true_ {};
|
||||
|
||||
} } } }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*`To define a 50 decimal digit type using `cpp_dec_float`,
|
||||
you must pass two template parameters to `boost::multiprecision::number`.
|
||||
|
||||
@@ -46,7 +89,9 @@ if desired, as shown below.
|
||||
*/
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*`Now `cpp_dec_float_50_noet` or `cpp_dec_float_50_et`
|
||||
can be used as a direct replacement for built-in types like `double` etc.
|
||||
@@ -70,6 +115,11 @@ BOOST_AUTO_TEST_CASE(cpp_float_test_check_close_noet)
|
||||
BOOST_CHECK_CLOSE(a, b, eps * 100); // Expected to pass (because tolerance is as percent).
|
||||
BOOST_CHECK_CLOSE_FRACTION(a, b, eps); // Expected to pass (because tolerance is as fraction).
|
||||
|
||||
#if !defined(BOOST_TEST_NO_VARIADIC)
|
||||
namespace tt = boost::test_tools;
|
||||
BOOST_TEST( a == b, tt::tolerance( tt::fpc::percent_tolerance( eps * 100 ) ) );
|
||||
BOOST_TEST( a == b, tt::tolerance( eps ) );
|
||||
#endif
|
||||
|
||||
//] [/expression_template_1]git
|
||||
|
||||
@@ -92,6 +142,12 @@ BOOST_AUTO_TEST_CASE(cpp_float_test_check_close_et)
|
||||
|
||||
BOOST_CHECK_CLOSE(a, b, eps * 100); // Expected to pass (because tolerance is as percent).
|
||||
BOOST_CHECK_CLOSE_FRACTION(a, b, eps); // Expected to pass (because tolerance is as fraction).
|
||||
|
||||
#if !defined(BOOST_TEST_NO_VARIADIC)
|
||||
namespace tt = boost::test_tools;
|
||||
BOOST_TEST( a == b, tt::tolerance( tt::fpc::percent_tolerance<cpp_dec_float_50_et>( eps * 100 ) ) );
|
||||
BOOST_TEST( a == b, tt::tolerance( eps ) );
|
||||
#endif
|
||||
|
||||
/*`Using `cpp_dec_float_50` with the default expression template use switched on,
|
||||
the compiler error message for `BOOST_CHECK_CLOSE_FRACTION(a, b, eps); would be:
|
||||
|
||||
Reference in New Issue
Block a user