Ticket #8272: test_multiprecision.patch

File test_multiprecision.patch, 4.8 KB (added by John Maddock, 10 years ago)

Patches to make Boost.Test work with expression template types.

  • boost/test/tools/floating_point_comparison.hpp

     
    1818// Boost.Test
    1919#include <boost/test/detail/global_typedef.hpp>
    2020#include <boost/test/tools/assertion_result.hpp>
    21 
     21#include <boost/type_traits/is_convertible.hpp>
    2222// Boost
    2323#include <boost/limits.hpp>  // for std::numeric_limits
    2424#include <boost/numeric/conversion/conversion_traits.hpp> // for numeric::conversion_traits
    2525#include <boost/static_assert.hpp>
    2626#include <boost/assert.hpp>
     27#include <boost/mpl/if.hpp>
    2728
    2829// STL
    2930#include <iosfwd>
     
    173174    // if one type is floating and the second integral we use floating type and
    174175    // value of integral type is promoted to the floating. The same for float and double
    175176    // But we don't want to compare two values of integral types using this tool.
    176     typedef typename numeric::conversion_traits<FPT1,FPT2>::supertype type;
     177    typedef typename mpl::if_c<
     178       is_convertible<FPT1, FPT2>::value && !is_convertible<FPT2, FPT1>::value,
     179       FPT2,
     180       typename mpl::if_c<
     181          !is_convertible<FPT1, FPT2>::value && is_convertible<FPT2, FPT1>::value,
     182          FPT1,
     183          typename numeric::conversion_traits<FPT1,FPT2>::supertype
     184       >::type
     185    >::type type;
    177186    BOOST_STATIC_ASSERT( !is_integral<type>::value );
    178187};
    179188
     
    204213    // Action method
    205214    bool                operator()( FPT left, FPT right ) const
    206215    {
    207         FPT diff              = fpc_detail::fpt_abs( left - right );
     216        FPT diff              = fpc_detail::fpt_abs( static_cast<FPT>(left - right) );
    208217        FPT fraction_of_right = fpc_detail::safe_fpt_division( diff, fpc_detail::fpt_abs( right ) );
    209218        FPT fraction_of_left  = fpc_detail::safe_fpt_division( diff, fpc_detail::fpt_abs( left ) );
    210219       
  • boost/test/tools/old/impl.hpp

     
    323323    {
    324324        return fpc::is_small( fpv, tolerance );
    325325    }
     326    template<typename FPT1, class FPT2>
     327    bool
     328    operator()( FPT1 fpv, FPT2 tolerance ) const
     329    {
     330        typedef typename fpc::comp_supertype<FPT1, FPT2>::type common_type;
     331        return fpc::is_small( static_cast<common_type>(fpv), static_cast<common_type>(tolerance));
     332    }
    326333};
    327334
    328335//____________________________________________________________________________//
  • libs/test/test/Jamfile.v2

     
    9191          [ test-btl-lib run : test_datasets_cxx11          : boost_unit_test_framework : : [ glob test_datasets_src/*.cpp ] : : <toolset>gcc:<cxxflags>-std=gnu++0x ]
    9292          # [ test-btl-lib run : config_file_iterator_test    : boost_unit_test_framework/<link>static ]
    9393          # [ test-btl-lib run : config_file_test             : boost_unit_test_framework/<link>static ]
     94          [ test-btl-lib run : test_expression_template_fpt   : boost_unit_test_framework ]
    9495        ;
    9596
    9697test-suite "multithreaded_test"
     
    103104 
    104105# Only run tests when explicitly requested
    105106# explicit test basics_test prg_exec_monitor_test unit_test_framework_test ;
     107
  • libs/test/test/test_expression_template_fpt.cpp

     
     1///////////////////////////////////////////////////////////////////////////////
     2//  Copyright 2013 John Maddock. Distributed under the Boost
     3//  Software License, Version 1.0. (See accompanying file
     4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6
     7#include <boost/multiprecision/cpp_dec_float.hpp>
     8#define BOOST_TEST_MODULE multiprecision
     9#include <boost/test/unit_test.hpp>
     10
     11BOOST_AUTO_TEST_CASE(multiprecision)
     12{
     13   using namespace boost::multiprecision;
     14
     15   cpp_dec_float_50 a(0), b(0), c(1);
     16   cpp_dec_float_50 eps = std::numeric_limits<cpp_dec_float_50>::epsilon();
     17
     18   BOOST_CHECK_EQUAL(a, b);
     19   BOOST_CHECK_NE(a, c);
     20   BOOST_CHECK_LE(a, b);
     21   BOOST_CHECK_GE(a, b);
     22   BOOST_CHECK_GT(c, a);
     23   BOOST_CHECK_LT(a, c);
     24
     25   BOOST_CHECK_SMALL(a, eps);
     26   BOOST_CHECK_SMALL(eps/2, eps);
     27
     28   b = c + 10 * eps;
     29
     30   BOOST_CHECK_CLOSE_FRACTION(b, c, eps * 20);
     31   BOOST_CHECK_CLOSE(b, c, eps * 20 * 100);
     32
     33   BOOST_CHECK_CLOSE_FRACTION(1 * b, c, eps * 20);
     34   BOOST_CHECK_CLOSE(1 * b, c, eps * 20 * 100);
     35}
     36