]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/dynamic_bitset/test/dyn_bitset_unit_tests2.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / dynamic_bitset / test / dyn_bitset_unit_tests2.cpp
CommitLineData
7c673cae
FG
1// -----------------------------------------------------------
2// Copyright (c) 2001 Jeremy Siek
3// Copyright (c) 2003-2006 Gennaro Prota
4// Copyright (c) 2014 Ahmed Charles
92f5a8d4 5// Copyright (c) 2018 Evgeny Shulgin
7c673cae
FG
6//
7// Distributed under the Boost Software License, Version 1.0.
8// (See accompanying file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt)
10//
11// -----------------------------------------------------------
12
13#include "bitset_test.hpp"
92f5a8d4
TL
14#include <boost/dynamic_bitset/dynamic_bitset.hpp>
15#include <boost/config.hpp>
7c673cae
FG
16
17
18template <typename Block>
19void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
20{
21 typedef boost::dynamic_bitset<Block> bitset_type;
22 typedef bitset_test< bitset_type > Tests;
23 const int bits_per_block = bitset_type::bits_per_block;
24
25 std::string long_string = get_long_string();
26
27 //=====================================================================
28 // Test operator&=
29 {
30 boost::dynamic_bitset<Block> lhs, rhs;
31 Tests::and_assignment(lhs, rhs);
32 }
33 {
34 boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
35 Tests::and_assignment(lhs, rhs);
36 }
37 {
38 boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
39 Tests::and_assignment(lhs, rhs);
40 }
41 {
42 boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
43 Tests::and_assignment(lhs, rhs);
44 }
45 //=====================================================================
46 // Test operator |=
47 {
48 boost::dynamic_bitset<Block> lhs, rhs;
49 Tests::or_assignment(lhs, rhs);
50 }
51 {
52 boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
53 Tests::or_assignment(lhs, rhs);
54 }
55 {
56 boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
57 Tests::or_assignment(lhs, rhs);
58 }
59 {
60 boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
61 Tests::or_assignment(lhs, rhs);
62 }
63 //=====================================================================
64 // Test operator^=
65 {
66 boost::dynamic_bitset<Block> lhs, rhs;
67 Tests::xor_assignment(lhs, rhs);
68 }
69 {
70 boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
71 Tests::xor_assignment(lhs, rhs);
72 }
73 {
74 boost::dynamic_bitset<Block> lhs(std::string("0")), rhs(std::string("1"));
75 Tests::xor_assignment(lhs, rhs);
76 }
77 {
78 boost::dynamic_bitset<Block> lhs(long_string), rhs(long_string);
79 Tests::xor_assignment(lhs, rhs);
80 }
81 //=====================================================================
82 // Test operator-=
83 {
84 boost::dynamic_bitset<Block> lhs, rhs;
85 Tests::sub_assignment(lhs, rhs);
86 }
87 {
88 boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
89 Tests::sub_assignment(lhs, rhs);
90 }
91 {
92 boost::dynamic_bitset<Block> lhs(std::string("0")), rhs(std::string("1"));
93 Tests::sub_assignment(lhs, rhs);
94 }
95 {
96 boost::dynamic_bitset<Block> lhs(long_string), rhs(long_string);
97 Tests::sub_assignment(lhs, rhs);
98 }
99 //=====================================================================
100 // Test operator<<=
101 { // case pos == 0
102 std::size_t pos = 0;
103 {
104 boost::dynamic_bitset<Block> b;
105 Tests::shift_left_assignment(b, pos);
106 }
107 {
108 boost::dynamic_bitset<Block> b(std::string("1010"));
109 Tests::shift_left_assignment(b, pos);
110 }
111 {
112 boost::dynamic_bitset<Block> b(long_string);
113 Tests::shift_left_assignment(b, pos);
114 }
115 }
116 {
117 // test with both multiple and
118 // non multiple of bits_per_block
119 const int how_many = 10;
120 for (int i = 1; i <= how_many; ++i) {
121 std::size_t multiple = i * bits_per_block;
122 std::size_t non_multiple = multiple - 1;
123 boost::dynamic_bitset<Block> b(long_string);
124
125 Tests::shift_left_assignment(b, multiple);
126 Tests::shift_left_assignment(b, non_multiple);
127 }
128 }
129 { // case pos == size()/2
130 std::size_t pos = long_string.size() / 2;
131 boost::dynamic_bitset<Block> b(long_string);
132 Tests::shift_left_assignment(b, pos);
133 }
134 { // case pos >= n
135 std::size_t pos = long_string.size();
136 boost::dynamic_bitset<Block> b(long_string);
137 Tests::shift_left_assignment(b, pos);
138 }
139 //=====================================================================
140 // Test operator>>=
141 { // case pos == 0
142 std::size_t pos = 0;
143 {
144 boost::dynamic_bitset<Block> b;
145 Tests::shift_right_assignment(b, pos);
146 }
147 {
148 boost::dynamic_bitset<Block> b(std::string("1010"));
149 Tests::shift_right_assignment(b, pos);
150 }
151 {
152 boost::dynamic_bitset<Block> b(long_string);
153 Tests::shift_right_assignment(b, pos);
154 }
155 }
156 {
157 // test with both multiple and
158 // non multiple of bits_per_block
159 const int how_many = 10;
160 for (int i = 1; i <= how_many; ++i) {
161 std::size_t multiple = i * bits_per_block;
162 std::size_t non_multiple = multiple - 1;
163 boost::dynamic_bitset<Block> b(long_string);
164
165 Tests::shift_right_assignment(b, multiple);
166 Tests::shift_right_assignment(b, non_multiple);
167 }
168
169 }
170 { // case pos == size()/2
171 std::size_t pos = long_string.size() / 2;
172 boost::dynamic_bitset<Block> b(long_string);
173 Tests::shift_right_assignment(b, pos);
174 }
175 { // case pos >= n
176 std::size_t pos = long_string.size();
177 boost::dynamic_bitset<Block> b(long_string);
178 Tests::shift_right_assignment(b, pos);
179 }
180 //=====================================================================
181 // test b.set()
182 {
183 boost::dynamic_bitset<Block> b;
184 Tests::set_all(b);
185 }
186 {
187 boost::dynamic_bitset<Block> b(std::string("0"));
188 Tests::set_all(b);
189 }
190 {
191 boost::dynamic_bitset<Block> b(long_string);
192 Tests::set_all(b);
193 }
194 //=====================================================================
195 // Test b.set(pos)
196 { // case pos >= b.size()
197 boost::dynamic_bitset<Block> b;
198 Tests::set_one(b, 0, true);
199 Tests::set_one(b, 0, false);
200 }
201 { // case pos < b.size()
202 boost::dynamic_bitset<Block> b(std::string("0"));
203 Tests::set_one(b, 0, true);
204 Tests::set_one(b, 0, false);
205 }
206 { // case pos == b.size() / 2
207 boost::dynamic_bitset<Block> b(long_string);
208 Tests::set_one(b, long_string.size()/2, true);
209 Tests::set_one(b, long_string.size()/2, false);
210 }
211 //=====================================================================
92f5a8d4
TL
212 // Test b.set(pos, len)
213 { // case size is 1
214 boost::dynamic_bitset<Block> b(std::string("0"));
215 Tests::set_segment(b, 0, 1, true);
216 Tests::set_segment(b, 0, 1, false);
217 }
218 { // case fill the whole set
219 boost::dynamic_bitset<Block> b(long_string);
220 Tests::set_segment(b, 0, b.size(), true);
221 Tests::set_segment(b, 0, b.size(), false);
222 }
223 { // case pos = size / 4, len = size / 2
224 boost::dynamic_bitset<Block> b(long_string);
225 Tests::set_segment(b, b.size() / 4, b.size() / 2, true);
226 Tests::set_segment(b, b.size() / 4, b.size() / 2, false);
227 }
228 { // case pos = block_size / 2, len = size - block_size
229 boost::dynamic_bitset<Block> b(long_string);
230 Tests::set_segment(b, boost::dynamic_bitset<Block>::bits_per_block / 2,
231 b.size() - boost::dynamic_bitset<Block>::bits_per_block, true);
232 Tests::set_segment(b, boost::dynamic_bitset<Block>::bits_per_block / 2,
233 b.size() - boost::dynamic_bitset<Block>::bits_per_block, false);
234 }
235 { // case pos = 1, len = size - 2
236 boost::dynamic_bitset<Block> b(long_string);
237 Tests::set_segment(b, 1, b.size() - 2, true);
238 Tests::set_segment(b, 1, b.size() - 2, false);
239 }
240 { // case pos = 3, len = 7
241 boost::dynamic_bitset<Block> b(long_string);
242 Tests::set_segment(b, 3, 7, true);
243 Tests::set_segment(b, 3, 7, false);
244 }
245 //=====================================================================
7c673cae
FG
246 // Test b.reset()
247 {
248 boost::dynamic_bitset<Block> b;
249 Tests::reset_all(b);
250 }
251 {
252 boost::dynamic_bitset<Block> b(std::string("0"));
253 Tests::reset_all(b);
254 }
255 {
256 boost::dynamic_bitset<Block> b(long_string);
257 Tests::reset_all(b);
258 }
259 //=====================================================================
260 // Test b.reset(pos)
261 { // case pos >= b.size()
262 boost::dynamic_bitset<Block> b;
263 Tests::reset_one(b, 0);
264 }
265 { // case pos < b.size()
266 boost::dynamic_bitset<Block> b(std::string("0"));
267 Tests::reset_one(b, 0);
268 }
269 { // case pos == b.size() / 2
270 boost::dynamic_bitset<Block> b(long_string);
271 Tests::reset_one(b, long_string.size()/2);
272 }
273 //=====================================================================
92f5a8d4
TL
274 // Test b.reset(pos, len)
275 { // case size is 1
276 boost::dynamic_bitset<Block> b(std::string("0"));
277 Tests::reset_segment(b, 0, 1);
278 }
279 { // case fill the whole set
280 boost::dynamic_bitset<Block> b(long_string);
281 Tests::reset_segment(b, 0, b.size());
282 }
283 { // case pos = size / 4, len = size / 2
284 boost::dynamic_bitset<Block> b(long_string);
285 Tests::reset_segment(b, b.size() / 4, b.size() / 2);
286 }
287 { // case pos = block_size / 2, len = size - block_size
288 boost::dynamic_bitset<Block> b(long_string);
289 Tests::reset_segment(b, boost::dynamic_bitset<Block>::bits_per_block / 2,
290 b.size() - boost::dynamic_bitset<Block>::bits_per_block);
291 }
292 { // case pos = 1, len = size - 2
293 boost::dynamic_bitset<Block> b(long_string);
294 Tests::reset_segment(b, 1, b.size() - 2);
295 }
296 { // case pos = 3, len = 7
297 boost::dynamic_bitset<Block> b(long_string);
298 Tests::reset_segment(b, 3, 7);
299 }
300 //=====================================================================
7c673cae
FG
301 // Test ~b
302 {
303 boost::dynamic_bitset<Block> b;
304 Tests::operator_flip(b);
305 }
306 {
307 boost::dynamic_bitset<Block> b(std::string("1"));
308 Tests::operator_flip(b);
309 }
310 {
311 boost::dynamic_bitset<Block> b(long_string);
312 Tests::operator_flip(b);
313 }
314 //=====================================================================
315 // Test b.flip()
316 {
317 boost::dynamic_bitset<Block> b;
318 Tests::flip_all(b);
319 }
320 {
321 boost::dynamic_bitset<Block> b(std::string("1"));
322 Tests::flip_all(b);
323 }
324 {
325 boost::dynamic_bitset<Block> b(long_string);
326 Tests::flip_all(b);
327 }
328 //=====================================================================
329 // Test b.flip(pos)
330 { // case pos >= b.size()
331 boost::dynamic_bitset<Block> b;
332 Tests::flip_one(b, 0);
333 }
334 { // case pos < b.size()
335 boost::dynamic_bitset<Block> b(std::string("0"));
336 Tests::flip_one(b, 0);
337 }
338 { // case pos == b.size() / 2
339 boost::dynamic_bitset<Block> b(long_string);
340 Tests::flip_one(b, long_string.size()/2);
341 }
92f5a8d4
TL
342 //=====================================================================
343 // Test b.flip(pos, len)
344 { // case size is 1
345 boost::dynamic_bitset<Block> b(std::string("0"));
346 Tests::flip_segment(b, 0, 1);
347 }
348 { // case fill the whole set
349 boost::dynamic_bitset<Block> b(long_string);
350 Tests::flip_segment(b, 0, b.size());
351 }
352 { // case pos = size / 4, len = size / 2
353 boost::dynamic_bitset<Block> b(long_string);
354 Tests::flip_segment(b, b.size() / 4, b.size() / 2);
355 }
356 { // case pos = block_size / 2, len = size - block_size
357 boost::dynamic_bitset<Block> b(long_string);
358 Tests::flip_segment(b, boost::dynamic_bitset<Block>::bits_per_block / 2,
359 b.size() - boost::dynamic_bitset<Block>::bits_per_block);
360 }
361 { // case pos = 1, len = size - 2
362 boost::dynamic_bitset<Block> b(long_string);
363 Tests::flip_segment(b, 1, b.size() - 2);
364 }
365 { // case pos = 3, len = 7
366 boost::dynamic_bitset<Block> b(long_string);
367 Tests::flip_segment(b, 3, 7);
368 }
7c673cae
FG
369}
370
371int
92f5a8d4 372main()
7c673cae
FG
373{
374 run_test_cases<unsigned char>();
375 run_test_cases<unsigned short>();
376 run_test_cases<unsigned int>();
377 run_test_cases<unsigned long>();
378# ifdef BOOST_HAS_LONG_LONG
379 run_test_cases< ::boost::ulong_long_type>();
380# endif
381
92f5a8d4 382 return boost::report_errors();
7c673cae 383}