1 // Boost static_min_max.hpp test program -----------------------------------//
2
3 // (C) Copyright Daryle Walker 2001.
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8 // See http://www.boost.org for most recent version including documentation.
9
10 // Revision History
11 // 23 Sep 2001 Initial version (Daryle Walker)
12
13 #include <boost/detail/lightweight_test.hpp> // for main, BOOST_TEST
14
15 #include <boost/cstdlib.hpp> // for boost::exit_success
16 #include <boost/integer/static_min_max.hpp> // for boost::static_signed_min, etc.
17
18 #include <iostream> // for std::cout (std::endl indirectly)
19
20
21 // Main testing function
22 int
main(int,char * [])23 main
24 (
25 int , // "argc" is unused
26 char * [] // "argv" is unused
27 )
28 {
29 using std::cout;
30 using std::endl;
31 using boost::static_signed_min;
32 using boost::static_signed_max;
33 using boost::static_unsigned_min;
34 using boost::static_unsigned_max;
35
36 // Two positives
37 cout << "Doing tests with two positive values." << endl;
38
39 BOOST_TEST( (static_signed_min< 9, 14>::value) == 9 );
40 BOOST_TEST( (static_signed_max< 9, 14>::value) == 14 );
41 BOOST_TEST( (static_signed_min<14, 9>::value) == 9 );
42 BOOST_TEST( (static_signed_max<14, 9>::value) == 14 );
43
44 BOOST_TEST( (static_unsigned_min< 9, 14>::value) == 9 );
45 BOOST_TEST( (static_unsigned_max< 9, 14>::value) == 14 );
46 BOOST_TEST( (static_unsigned_min<14, 9>::value) == 9 );
47 BOOST_TEST( (static_unsigned_max<14, 9>::value) == 14 );
48
49 // Two negatives
50 cout << "Doing tests with two negative values." << endl;
51
52 BOOST_TEST( (static_signed_min< -8, -101>::value) == -101 );
53 BOOST_TEST( (static_signed_max< -8, -101>::value) == -8 );
54 BOOST_TEST( (static_signed_min<-101, -8>::value) == -101 );
55 BOOST_TEST( (static_signed_max<-101, -8>::value) == -8 );
56
57 // With zero
58 cout << "Doing tests with zero and a positive or negative value." << endl;
59
60 BOOST_TEST( (static_signed_min< 0, 14>::value) == 0 );
61 BOOST_TEST( (static_signed_max< 0, 14>::value) == 14 );
62 BOOST_TEST( (static_signed_min<14, 0>::value) == 0 );
63 BOOST_TEST( (static_signed_max<14, 0>::value) == 14 );
64
65 BOOST_TEST( (static_unsigned_min< 0, 14>::value) == 0 );
66 BOOST_TEST( (static_unsigned_max< 0, 14>::value) == 14 );
67 BOOST_TEST( (static_unsigned_min<14, 0>::value) == 0 );
68 BOOST_TEST( (static_unsigned_max<14, 0>::value) == 14 );
69
70 BOOST_TEST( (static_signed_min< 0, -101>::value) == -101 );
71 BOOST_TEST( (static_signed_max< 0, -101>::value) == 0 );
72 BOOST_TEST( (static_signed_min<-101, 0>::value) == -101 );
73 BOOST_TEST( (static_signed_max<-101, 0>::value) == 0 );
74
75 // With identical
76 cout << "Doing tests with two identical values." << endl;
77
78 BOOST_TEST( (static_signed_min<0, 0>::value) == 0 );
79 BOOST_TEST( (static_signed_max<0, 0>::value) == 0 );
80 BOOST_TEST( (static_unsigned_min<0, 0>::value) == 0 );
81 BOOST_TEST( (static_unsigned_max<0, 0>::value) == 0 );
82
83 BOOST_TEST( (static_signed_min<14, 14>::value) == 14 );
84 BOOST_TEST( (static_signed_max<14, 14>::value) == 14 );
85 BOOST_TEST( (static_unsigned_min<14, 14>::value) == 14 );
86 BOOST_TEST( (static_unsigned_max<14, 14>::value) == 14 );
87
88 BOOST_TEST( (static_signed_min< -101, -101>::value) == -101 );
89 BOOST_TEST( (static_signed_max< -101, -101>::value) == -101 );
90
91 return boost::report_errors();
92 }
93