Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/numeric/conversion/test/bounds_test.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 3.0 KB
Line 
1//  © 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)
5
6//  See library home page at http://www.boost.org/libs/numeric/conversion
7//
8// Contact the author at: fernando_cacciola@hotmail.com
9//
10#include<typeinfo>
11#include<iostream>
12#include<iomanip>    
13
14#include "boost/numeric/conversion/bounds.hpp"
15
16#ifdef __BORLANDC__
17#pragma hdrstop
18#endif
19
20#include "test_helpers.cpp"
21
22using namespace std ;
23using namespace boost ;
24using namespace numeric ;
25
26// Test the fields of boost::numeric::bounds<> against the expected values.
27//
28template<class T>
29void test_bounds( T expected_lowest, T expected_highest, T expected_smallest )
30{
31  T lowest   = bounds<T>::lowest  () ;
32  T highest  = bounds<T>::highest () ;
33  T smallest = bounds<T>::smallest() ;
34
35  BOOST_CHECK_MESSAGE ( lowest == expected_lowest,
36                        "bounds<" << typeid(T).name() << ">::lowest() = " << printable(lowest) << ". Expected " << printable(expected_lowest)
37                      ) ;
38
39  BOOST_CHECK_MESSAGE ( highest == expected_highest,
40                        "bounds<" << typeid(T).name() << ">::highest() = " << printable(highest) << ". Expected " << printable(expected_highest)
41                      ) ;
42
43  BOOST_CHECK_MESSAGE ( smallest == expected_smallest,
44                        "bounds<" << typeid(T).name() << ">::smallest() = " << printable(smallest) << ". Expected " << printable(expected_smallest)
45                      ) ;
46}
47
48
49template<class T>
50void test_bounds_integer( MATCH_FNTPL_ARG(T) )
51{
52  test_bounds(  numeric_limits<T>::min BOOST_PREVENT_MACRO_SUBSTITUTION()
53              , numeric_limits<T>::max BOOST_PREVENT_MACRO_SUBSTITUTION()
54              , static_cast<T>(1)
55             ) ;
56}
57template<class T>
58void test_bounds_float( MATCH_FNTPL_ARG(T))
59{
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 ()
63             ) ;
64}
65
66void test_bounds_integers()
67{
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) ) ;
77}
78
79void test_bounds_floats()
80{
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) );
84}
85
86void test_bounds()
87{
88  test_bounds_integers() ;
89  test_bounds_floats  () ;
90}
91
92
93int test_main( int, char * [] )
94{
95  cout << setprecision( std::numeric_limits<long double>::digits10 ) ;
96
97  test_bounds();
98
99  return 0;
100}
101
Note: See TracBrowser for help on using the repository browser.