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) |
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 BOOST_BORLANDC |
17 | #pragma hdrstop |
18 | #endif |
19 | |
20 | #include "test_helpers.cpp" |
21 | |
22 | using namespace std ; |
23 | using namespace boost ; |
24 | using namespace numeric ; |
25 | |
26 | // Test the fields of boost::numeric::bounds<> against the expected values. |
27 | // |
28 | template<class T> |
29 | void 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_TEST_EQ(lowest, expected_lowest); |
36 | |
37 | BOOST_TEST_EQ(highest, expected_highest); |
38 | |
39 | BOOST_TEST_EQ(smallest, expected_smallest); |
40 | } |
41 | |
42 | |
43 | template<class T> |
44 | void test_bounds_integer( MATCH_FNTPL_ARG(T) ) |
45 | { |
46 | test_bounds( numeric_limits<T>::min BOOST_PREVENT_MACRO_SUBSTITUTION() |
47 | , numeric_limits<T>::max BOOST_PREVENT_MACRO_SUBSTITUTION() |
48 | , static_cast<T>(1) |
49 | ) ; |
50 | } |
51 | template<class T> |
52 | void test_bounds_float( MATCH_FNTPL_ARG(T)) |
53 | { |
54 | test_bounds( -numeric_limits<T>::max BOOST_PREVENT_MACRO_SUBSTITUTION () |
55 | , numeric_limits<T>::max BOOST_PREVENT_MACRO_SUBSTITUTION () |
56 | , numeric_limits<T>::min BOOST_PREVENT_MACRO_SUBSTITUTION () |
57 | ) ; |
58 | } |
59 | |
60 | void test_bounds_integers() |
61 | { |
62 | test_bounds_integer( SET_FNTPL_ARG(unsigned char) ) ; |
63 | test_bounds_integer( SET_FNTPL_ARG(signed char) ) ; |
64 | test_bounds_integer( SET_FNTPL_ARG(char) ) ; |
65 | test_bounds_integer( SET_FNTPL_ARG(unsigned short) ) ; |
66 | test_bounds_integer( SET_FNTPL_ARG(short) ) ; |
67 | test_bounds_integer( SET_FNTPL_ARG(unsigned int) ) ; |
68 | test_bounds_integer( SET_FNTPL_ARG(int) ) ; |
69 | test_bounds_integer( SET_FNTPL_ARG(unsigned long) ) ; |
70 | test_bounds_integer( SET_FNTPL_ARG(long) ) ; |
71 | } |
72 | |
73 | void test_bounds_floats() |
74 | { |
75 | test_bounds_float( SET_FNTPL_ARG(float) ); |
76 | test_bounds_float( SET_FNTPL_ARG(double) ); |
77 | test_bounds_float( SET_FNTPL_ARG(long double) ); |
78 | } |
79 | |
80 | void test_bounds() |
81 | { |
82 | test_bounds_integers() ; |
83 | test_bounds_floats () ; |
84 | } |
85 | |
86 | |
87 | int main( ) |
88 | { |
89 | cout << setprecision( std::numeric_limits<long double>::digits10 ) ; |
90 | |
91 | test_bounds(); |
92 | |
93 | return boost::report_errors(); |
94 | } |
95 | |
96 | |