1 // Boost static_log2.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 // 01 Oct 2001 Initial version (Daryle Walker)
12
13 #include <boost/detail/lightweight_test.hpp> // for main
14
15 #include <boost/cstdlib.hpp> // for boost::exit_success
16 #include <boost/integer/static_log2.hpp> // for boost::static_log2
17
18 #include <iostream> // for std::cout (std::endl indirectly)
19
20
21 // Macros to compact code
22 #define PRIVATE_LB_TEST( v, e ) BOOST_TEST( ::boost::static_log2<v>::value == e )
23
24 #define PRIVATE_PRINT_LB( v ) ::std::cout << "boost::static_log2<" << (v) \
25 << "> = " << ::boost::static_log2< (v) >::value << '.' << ::std::endl
26
27 // Control to check for a compile-time error
28 #ifndef CONTROL_LB_0_TEST
29 #define PRIVATE_LB_0_TEST
30 #else
31 #define PRIVATE_LB_0_TEST PRIVATE_PRINT_LB( 0 )
32 #endif
33
34
35 // Main testing function
36 int
main(int,char * [])37 main
38 (
39 int , // "argc" is unused
40 char * [] // "argv" is unused
41 )
42 {
43 std::cout << "Doing tests on static_log2." << std::endl;
44
45 PRIVATE_LB_0_TEST;
46
47 PRIVATE_LB_TEST( 1, 0 );
48
49 PRIVATE_LB_TEST( 2, 1 );
50 PRIVATE_LB_TEST( 3, 1 );
51
52 PRIVATE_LB_TEST( 4, 2 );
53 PRIVATE_LB_TEST( 5, 2 );
54 PRIVATE_LB_TEST( 6, 2 );
55 PRIVATE_LB_TEST( 7, 2 );
56
57 PRIVATE_LB_TEST( 8, 3 );
58 PRIVATE_LB_TEST( 9, 3 );
59 PRIVATE_LB_TEST( 10, 3 );
60 PRIVATE_LB_TEST( 11, 3 );
61 PRIVATE_LB_TEST( 12, 3 );
62 PRIVATE_LB_TEST( 13, 3 );
63 PRIVATE_LB_TEST( 14, 3 );
64 PRIVATE_LB_TEST( 15, 3 );
65
66 PRIVATE_LB_TEST( 16, 4 );
67 PRIVATE_LB_TEST( 17, 4 );
68 PRIVATE_LB_TEST( 18, 4 );
69 PRIVATE_LB_TEST( 19, 4 );
70 PRIVATE_LB_TEST( 20, 4 );
71 PRIVATE_LB_TEST( 21, 4 );
72 PRIVATE_LB_TEST( 22, 4 );
73 PRIVATE_LB_TEST( 23, 4 );
74 PRIVATE_LB_TEST( 24, 4 );
75 PRIVATE_LB_TEST( 25, 4 );
76 PRIVATE_LB_TEST( 26, 4 );
77 PRIVATE_LB_TEST( 27, 4 );
78 PRIVATE_LB_TEST( 28, 4 );
79 PRIVATE_LB_TEST( 29, 4 );
80 PRIVATE_LB_TEST( 30, 4 );
81 PRIVATE_LB_TEST( 31, 4 );
82
83 PRIVATE_LB_TEST( 32, 5 );
84 PRIVATE_LB_TEST( 33, 5 );
85 PRIVATE_LB_TEST( 34, 5 );
86 PRIVATE_LB_TEST( 35, 5 );
87 PRIVATE_LB_TEST( 36, 5 );
88 PRIVATE_LB_TEST( 37, 5 );
89 PRIVATE_LB_TEST( 38, 5 );
90 PRIVATE_LB_TEST( 39, 5 );
91 PRIVATE_LB_TEST( 40, 5 );
92
93 PRIVATE_LB_TEST( 63, 5 );
94
95 PRIVATE_LB_TEST( 64, 6 );
96 PRIVATE_LB_TEST( 65, 6 );
97
98 PRIVATE_LB_TEST( 127, 6 );
99
100 PRIVATE_LB_TEST( 128, 7 );
101 PRIVATE_LB_TEST( 129, 7 );
102
103 PRIVATE_LB_TEST( 255, 7 );
104
105 PRIVATE_LB_TEST( 256, 8 );
106 PRIVATE_LB_TEST( 257, 8 );
107
108 PRIVATE_LB_TEST( 511, 8 );
109
110 PRIVATE_LB_TEST( 512, 9 );
111 PRIVATE_LB_TEST( 513, 9 );
112
113 PRIVATE_LB_TEST( 1023, 9 );
114
115 PRIVATE_LB_TEST( 1024, 10 );
116 PRIVATE_LB_TEST( 1025, 10 );
117
118 PRIVATE_LB_TEST( 2047, 10 );
119
120 PRIVATE_LB_TEST( 2048, 11 );
121 PRIVATE_LB_TEST( 2049, 11 );
122
123 PRIVATE_LB_TEST( 4095, 11 );
124
125 PRIVATE_LB_TEST( 4096, 12 );
126 PRIVATE_LB_TEST( 4097, 12 );
127
128 PRIVATE_LB_TEST( 8191, 12 );
129
130 PRIVATE_LB_TEST( 8192, 13 );
131 PRIVATE_LB_TEST( 8193, 13 );
132
133 PRIVATE_LB_TEST( 16383, 13 );
134
135 PRIVATE_LB_TEST( 16384, 14 );
136 PRIVATE_LB_TEST( 16385, 14 );
137
138 PRIVATE_LB_TEST( 32767, 14 );
139
140 PRIVATE_LB_TEST( 32768, 15 );
141 PRIVATE_LB_TEST( 32769, 15 );
142
143 PRIVATE_LB_TEST( 65535, 15 );
144
145 PRIVATE_LB_TEST( 65536, 16 );
146 PRIVATE_LB_TEST( 65537, 16 );
147
148 return boost::report_errors();
149 }
150