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