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 | |
---|
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_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 | |
---|
49 | template<class T> |
---|
50 | void 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 | } |
---|
57 | template<class T> |
---|
58 | void 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 | |
---|
66 | void 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 | |
---|
79 | void 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 | |
---|
86 | void test_bounds() |
---|
87 | { |
---|
88 | test_bounds_integers() ; |
---|
89 | test_bounds_floats () ; |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | int test_main( int, char * [] ) |
---|
94 | { |
---|
95 | cout << setprecision( std::numeric_limits<long double>::digits10 ) ; |
---|
96 | |
---|
97 | test_bounds(); |
---|
98 | |
---|
99 | return 0; |
---|
100 | } |
---|
101 | |
---|