]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/conversion/test/bounds_test.cpp
1 // (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
2 // Use, modification, and distribution is subject to the Boost Software
3 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See library home page at http://www.boost.org/libs/numeric/conversion
8 // Contact the author at: fernando_cacciola@hotmail.com
14 #include "boost/numeric/conversion/bounds.hpp"
20 #include "test_helpers.cpp"
23 using namespace boost
;
24 using namespace numeric
;
26 // Test the fields of boost::numeric::bounds<> against the expected values.
29 void test_bounds( T expected_lowest
, T expected_highest
, T expected_smallest
)
31 T lowest
= bounds
<T
>::lowest () ;
32 T highest
= bounds
<T
>::highest () ;
33 T smallest
= bounds
<T
>::smallest() ;
35 BOOST_CHECK_MESSAGE ( lowest
== expected_lowest
,
36 "bounds<" << typeid(T
).name() << ">::lowest() = " << printable(lowest
) << ". Expected " << printable(expected_lowest
)
39 BOOST_CHECK_MESSAGE ( highest
== expected_highest
,
40 "bounds<" << typeid(T
).name() << ">::highest() = " << printable(highest
) << ". Expected " << printable(expected_highest
)
43 BOOST_CHECK_MESSAGE ( smallest
== expected_smallest
,
44 "bounds<" << typeid(T
).name() << ">::smallest() = " << printable(smallest
) << ". Expected " << printable(expected_smallest
)
50 void test_bounds_integer( MATCH_FNTPL_ARG(T
) )
52 test_bounds( numeric_limits
<T
>::min
BOOST_PREVENT_MACRO_SUBSTITUTION()
53 , numeric_limits
<T
>::max
BOOST_PREVENT_MACRO_SUBSTITUTION()
58 void test_bounds_float( MATCH_FNTPL_ARG(T
))
60 test_bounds( -numeric_limits
<T
>::max
BOOST_PREVENT_MACRO_SUBSTITUTION ()
61 , numeric_limits
<T
>::max
BOOST_PREVENT_MACRO_SUBSTITUTION ()
62 , numeric_limits
<T
>::min
BOOST_PREVENT_MACRO_SUBSTITUTION ()
66 void test_bounds_integers()
68 test_bounds_integer( SET_FNTPL_ARG(unsigned char) ) ;
69 test_bounds_integer( SET_FNTPL_ARG(signed char) ) ;
70 test_bounds_integer( SET_FNTPL_ARG(char) ) ;
71 test_bounds_integer( SET_FNTPL_ARG(unsigned short) ) ;
72 test_bounds_integer( SET_FNTPL_ARG(short) ) ;
73 test_bounds_integer( SET_FNTPL_ARG(unsigned int) ) ;
74 test_bounds_integer( SET_FNTPL_ARG(int) ) ;
75 test_bounds_integer( SET_FNTPL_ARG(unsigned long) ) ;
76 test_bounds_integer( SET_FNTPL_ARG(long) ) ;
79 void test_bounds_floats()
81 test_bounds_float( SET_FNTPL_ARG(float) );
82 test_bounds_float( SET_FNTPL_ARG(double) );
83 test_bounds_float( SET_FNTPL_ARG(long double) );
88 test_bounds_integers() ;
89 test_bounds_floats () ;
93 int test_main( int, char * [] )
95 cout
<< setprecision( std::numeric_limits
<long double>::digits10
) ;