File: bitset.cpp

package info (click to toggle)
tiledarray 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 9,568 kB
  • sloc: cpp: 53,449; javascript: 1,599; sh: 393; ansic: 226; python: 223; xml: 195; makefile: 36
file content (659 lines) | stat: -rw-r--r-- 18,624 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
/*
 * This file is a part of TiledArray.
 * Copyright (C) 2013  Virginia Tech
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "TiledArray/bitset.h"
#include <algorithm>
#include "tiledarray.h"
#include "unit_test_config.h"

using namespace TiledArray;

struct BitsetFixture {
  typedef TiledArray::detail::Bitset<> Bitset;

  BitsetFixture() : set(size) {}

  static const std::size_t size;
  static const std::size_t blocks;
  Bitset set;
};

const std::size_t BitsetFixture::size =
    sizeof(BitsetFixture::Bitset::block_type) * 8 * 10.5;
const std::size_t BitsetFixture::blocks = 11;

// =============================================================================
// Bitset Test Suite

BOOST_FIXTURE_TEST_SUITE(bitset_suite, BitsetFixture)

BOOST_AUTO_TEST_CASE(size_constructor) {
  // Check for error free construction
  BOOST_REQUIRE_NO_THROW(Bitset b(64));

  Bitset b(64);
  // Check that the size of the bitset is correct
  BOOST_CHECK_EQUAL(b.size(), 64ul);
  BOOST_CHECK_EQUAL(b.num_blocks(), 1ul);

  // check that all bits are correctly initialized to false.
  for (std::size_t i = 0; i < b.size(); ++i) BOOST_CHECK(!b[i]);
}

BOOST_AUTO_TEST_CASE(array_constructor) {
  std::array<int, 125> a;
  std::fill(a.begin(), a.end(), 1);
  // Check for error free copy construction
  BOOST_REQUIRE_NO_THROW(Bitset b(a.begin(), a.end()));

  Bitset b(a.begin(), a.end());
  // Check that the size of the bitset is correct
  BOOST_CHECK_EQUAL(b.size(), 125ul);
  BOOST_CHECK_EQUAL(b.num_blocks(), 2ul);

  // check that all bits are correctly initialized to false.
  for (std::size_t i = 0; i < b.size(); ++i) BOOST_CHECK(b[i]);
}

BOOST_AUTO_TEST_CASE(copy_constructor) {
  // Check for error free copy construction
  BOOST_REQUIRE_NO_THROW(Bitset b(set));

  Bitset b(set);
  // Check that the size of the bitset is correct
  BOOST_CHECK_EQUAL(b.size(), size);
  BOOST_CHECK_EQUAL(b.size(), set.size());
  BOOST_CHECK_EQUAL(b.num_blocks(), blocks);
  BOOST_CHECK_EQUAL(b.num_blocks(), set.num_blocks());

  // check that all bits are correctly initialized to false.
  for (std::size_t i = 0; i < b.size(); ++i) BOOST_CHECK(!b[i]);
}

BOOST_AUTO_TEST_CASE(get) { BOOST_CHECK(set.get() != NULL); }

BOOST_AUTO_TEST_CASE(set_size) { BOOST_CHECK_EQUAL(set.size(), size); }

BOOST_AUTO_TEST_CASE(num_blocks) {
  BOOST_CHECK_EQUAL(set.num_blocks(), blocks);
}

BOOST_AUTO_TEST_CASE(accessor) {
  // check that all bits are correctly initialized to false.
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(!set[i]);

    // Check that exceptions are thrown when accessing an element that is out of
    // range.
#ifdef TA_EXCEPTION_ERROR
  BOOST_CHECK_THROW(set[set.size()], Exception);
  BOOST_CHECK_THROW(set[set.size() + 1], Exception);
#endif  // TA_EXCEPTION_ERROR
}

BOOST_AUTO_TEST_CASE(set_bit) {
  // Check that the bits are not set
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(!set[i]);

  // Check that we can set all bits
  for (std::size_t i = 0; i < set.size(); ++i) {
    set.set(i);

    for (std::size_t ii = 0; ii < set.size(); ++ii) {
      if (ii <= i)
        BOOST_CHECK(set[ii]);  // Check bits that are set
      else
        BOOST_CHECK(!set[ii]);  // Check bits that are not set
    }

    // Check setting a bit that is already set.
    set.set(i);
    BOOST_CHECK(set[i]);
  }

  // Check that we can unset all bits
  for (std::size_t i = 0; i < set.size(); ++i) {
    set.set(i, false);

    for (std::size_t ii = 0; ii < set.size(); ++ii) {
      if (ii <= i)
        BOOST_CHECK(!set[ii]);  // Check bits that are not set
      else
        BOOST_CHECK(set[ii]);  // Check bits that are set
    }

    // Check setting a bit that is already set.
    set.set(i, false);
    BOOST_CHECK(!set[i]);
  }

  // Check that exceptions are thrown when accessing an element that is out of
  // range.
#ifdef TA_EXCEPTION_ERROR
  BOOST_CHECK_THROW(set.set(set.size()), Exception);
  BOOST_CHECK_THROW(set.set(set.size() + 1), Exception);
#endif  // TA_EXCEPTION_ERROR
}

BOOST_AUTO_TEST_CASE(set_all) {
  // Check that the bits are not set
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(!set[i]);

  set.set();

  // Check that the bits are set
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(set[i]);

  set.set();

  // Check that the bits are still set
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(set[i]);
}

BOOST_AUTO_TEST_CASE(set_range) {
  // Check that the bits are not set
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(!set[i]);

  set.set_range(10, 20);

  // Check that the bits are set
  std::size_t i = 0ul;
  for (; i < 10ul; ++i) {
    BOOST_CHECK(!set[i]);
    if (set[i]) std::cout << "i = " << i << "\n";
  }
  for (; i <= 20; ++i) {
    BOOST_CHECK(set[i]);
    if (!set[i]) std::cout << "i = " << i << "\n";
  }
  for (; i < size; ++i) {
    BOOST_CHECK(!set[i]);
    if (set[i]) std::cout << "i = " << i << "\n";
  }

  set.set_range(30, 225);

  // Check that the bits are setset
  for (i = 0ul; i < 10ul; ++i) {
    BOOST_CHECK(!set[i]);
    if (set[i]) std::cout << "i = " << i << "\n";
  }
  for (; i <= 20; ++i) {
    BOOST_CHECK(set[i]);
    if (!set[i]) std::cout << "i = " << i << "\n";
  }
  for (; i < 30ul; ++i) {
    BOOST_CHECK(!set[i]);
    if (set[i]) std::cout << "i = " << i << "\n";
  }
  for (; i <= 225; ++i) {
    BOOST_CHECK(set[i]);
    if (!set[i]) std::cout << "i = " << i << "\n";
  }
  for (; i < size; ++i) {
    BOOST_CHECK(!set[i]);
    if (set[i]) std::cout << "i = " << i << "\n";
  }
}

BOOST_AUTO_TEST_CASE(reset_bit) {
  set.set();

  // Check resetting a bit
  for (std::size_t i = 0; i < set.size(); ++i) {
    set.reset(i);

    for (std::size_t ii = 0; ii < set.size(); ++ii) {
      if (ii <= i)
        BOOST_CHECK(!set[ii]);  // Check bits that are not set
      else
        BOOST_CHECK(set[ii]);  // Check bits that are set
    }
  }

  // Check resetting a bit that is not set
  for (std::size_t i = 0; i < set.size(); ++i) {
    set.reset(i);

    for (std::size_t ii = 0; ii < set.size(); ++ii)
      BOOST_CHECK(!set[ii]);  // Check bits that are not set
  }

  // Check that exceptions are thrown when accessing an element that is out of
  // range.
#ifdef TA_EXCEPTION_ERROR
  BOOST_CHECK_THROW(set.reset(set.size()), Exception);
  BOOST_CHECK_THROW(set.reset(set.size() + 1), Exception);
#endif  // TA_EXCEPTION_ERROR
}

BOOST_AUTO_TEST_CASE(reset_all) {
  set.reset();

  // Check that the bits are not set
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(!set[i]);

  set.set();
  set.reset();

  // Check that the bits are set
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(!set[i]);
}

BOOST_AUTO_TEST_CASE(bit_flip) {
  // Check that the bits are not set
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(!set[i]);

  // Check that we can set all bits
  for (std::size_t i = 0; i < set.size(); ++i) {
    set.flip(i);

    for (std::size_t ii = 0; ii < set.size(); ++ii) {
      if (ii <= i)
        BOOST_CHECK(set[ii]);  // Check bits that are set
      else
        BOOST_CHECK(!set[ii]);  // Check bits that are not set
    }
  }

  // Check that we can unset all bits
  for (std::size_t i = 0; i < set.size(); ++i) {
    set.flip(i);

    for (std::size_t ii = 0; ii < set.size(); ++ii) {
      if (ii <= i)
        BOOST_CHECK(!set[ii]);  // Check bits that are not set
      else
        BOOST_CHECK(set[ii]);  // Check bits that are set
    }
  }

  // Check that exceptions are thrown when accessing an element that is out of
  // range.
#ifdef TA_EXCEPTION_ERROR
  BOOST_CHECK_THROW(set.flip(set.size()), Exception);
  BOOST_CHECK_THROW(set.flip(set.size() + 1), Exception);
#endif  // TA_EXCEPTION_ERROR
}

BOOST_AUTO_TEST_CASE(flip_all) {
  set.flip();

  // Check that the bits are set
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(set[i]);

  set.flip();

  // Check that the bits are not set
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(!set[i]);

  // Check that we can flip alternating bits
  for (std::size_t i = 0; i < set.size(); ++i)
    if (i % 2) set.flip(i);

  set.flip();

  for (std::size_t i = 0; i < set.size(); ++i) {
    if (i % 2)
      BOOST_CHECK(!set[i]);
    else
      BOOST_CHECK(set[i]);
  }
}

BOOST_AUTO_TEST_CASE(assignment) {
  // Fill bitset with random data
  std::size_t n = size * 0.25;
  GlobalFixture::world->srand(27);
  for (std::size_t i = 0; i < n; ++i)
    set.set(std::size_t(GlobalFixture::world->rand()) % size);

  Bitset b(size);

  // Check that assignment does not throw.
  BOOST_REQUIRE_NO_THROW(b = set);

  // Check that all bits were copied from set.
  BOOST_CHECK_EQUAL(b.size(), set.size());
  for (std::size_t i = 0ul; i < set.size(); ++i) {
    BOOST_REQUIRE_NO_THROW(b[i]);
    BOOST_CHECK(((b[i] != 0ul) && (set[i] != 0ul)) ||
                ((b[i] == 0ul) && (set[i] == 0ul)));
  }

  // Check that assignment of bitsets with different size is done correctly.
  Bitset small(size / 2);
  small.set();
  small = set;

  BOOST_CHECK_EQUAL(small.size(), set.size());
  for (std::size_t i = 0ul; i < set.size(); ++i) {
    BOOST_REQUIRE_NO_THROW(small[i]);
    BOOST_CHECK(((small[i] != 0ul) && (set[i] != 0ul)) ||
                ((small[i] == 0ul) && (set[i] == 0ul)));
  }

  // Check that assignment of bitsets with different size is done correctly.
  Bitset big(size * 2);
  big.set();
  big = set;

  BOOST_CHECK_EQUAL(big.size(), set.size());
  BOOST_CHECK_EQUAL(big.num_blocks(), set.num_blocks());
  for (std::size_t i = 0ul; i < set.size(); ++i) {
    BOOST_REQUIRE_NO_THROW(big[i]);
    BOOST_CHECK(((big[i] != 0ul) && (set[i] != 0ul)) ||
                ((big[i] == 0ul) && (set[i] == 0ul)));
  }
}

BOOST_AUTO_TEST_CASE(bit_assignment) {
  Bitset even(size);
  Bitset odd(size);
  for (std::size_t i = 0; i < set.size(); ++i) {
    set.set(i);
    if (i % 2)
      even.set(i);
    else
      odd.set(i);
  }

  // Check that and-assignment does not throw.
  BOOST_REQUIRE_NO_THROW(set &= even);

  // Check for correct and-assignement (evens are set)
  for (std::size_t i = 0; i < set.size(); ++i) {
    if (i % 2)
      BOOST_CHECK(set[i]);
    else
      BOOST_CHECK(!set[i]);
  }

  // Check that or-assignment does not throw.
  BOOST_REQUIRE_NO_THROW(set |= odd);

  // Check for correct or-assignement (all are set)
  for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(set[i]);

  BOOST_REQUIRE_NO_THROW(set ^= odd);
  // Check for correct and-assignement (evens are set)
  for (std::size_t i = 0; i < set.size(); ++i) {
    if (i % 2)
      BOOST_CHECK(set[i]);
    else
      BOOST_CHECK(!set[i]);
  }

  // Check that assignment of bitsets with different size throws.
#ifdef TA_EXCEPTION_ERROR
  Bitset bad(size / 2);
  BOOST_CHECK_THROW(bad &= set, Exception);
  BOOST_CHECK_THROW(bad |= set, Exception);
  BOOST_CHECK_THROW(bad ^= set, Exception);
#endif  // TA_EXCEPTION_ERROR
}

BOOST_AUTO_TEST_CASE(bit_operators) {
  Bitset even(size);
  Bitset odd(size);
  for (std::size_t i = 0; i < set.size(); ++i) {
    set.set(i);
    if (i % 2)
      even.set(i);
    else
      odd.set(i);
  }

  // Check and-operator
  set = even & even;

  // Check for correct and-assignement (evens are set)
  for (std::size_t i = 0; i < set.size(); ++i) {
    if (i % 2)
      BOOST_CHECK(set[i]);
    else
      BOOST_CHECK(!set[i]);
  }

  set = even & odd;

  // Check for correct and-assignement (evens are set)
  for (std::size_t i = 0; i < set.size(); ++i) {
    BOOST_CHECK(!set[i]);
  }

  // Check or-operator
  set = even | even;

  // Check for correct and-assignement (evens are set)
  for (std::size_t i = 0; i < set.size(); ++i) {
    if (i % 2)
      BOOST_CHECK(set[i]);
    else
      BOOST_CHECK(!set[i]);
  }

  set = even | odd;

  // Check for correct and-assignement (evens are set)
  for (std::size_t i = 0; i < set.size(); ++i) {
    BOOST_CHECK(set[i]);
  }

  // Check xor-operator
  set = even ^ even;

  // Check for correct and-assignement (evens are set)
  for (std::size_t i = 0; i < set.size(); ++i) {
    BOOST_CHECK(!set[i]);
  }

  set = even ^ odd;

  // Check for correct and-assignement (evens are set)
  for (std::size_t i = 0; i < set.size(); ++i) {
    BOOST_CHECK(set[i]);
  }

  // Check that assignment of bitsets with different size throws.
#ifdef TA_EXCEPTION_ERROR
  Bitset bad(size / 2);
  BOOST_CHECK_THROW(bad & set, Exception);
  BOOST_CHECK_THROW(bad | set, Exception);
  BOOST_CHECK_THROW(bad ^ set, Exception);
#endif  // TA_EXCEPTION_ERROR
}

BOOST_AUTO_TEST_CASE(left_shift_assign) {
  // Fill bitset with random data
  std::size_t n = size * 0.25;
  GlobalFixture::world->srand(27);
  for (std::size_t i = 0; i < n; ++i)
    set.set(std::size_t(GlobalFixture::world->rand()) % size);

  // Check each bit shift from 0 to size
  for (std::size_t shift = 0; shift <= size; ++shift) {
    // Shift bitset data
    Bitset temp = set;
    temp <<= shift;

    // Check that the head is filled with zeros
    std::size_t i = 0;
    std::size_t j = 0;
    while ((i < shift) && (i < size)) {
      BOOST_CHECK(temp[i] == 0ul);
      if (temp[i]) std::cout << "i = " << i << "\n";
      ++i;
    }
    // Check that the data has been shifted correctly
    while (i < size) {
      BOOST_CHECK(((temp[i] != 0ul) && (set[j] != 0ul)) ||
                  ((temp[i] == 0ul) && (set[j] == 0ul)));
      if (!(((temp[i] != 0ul) && (set[j] != 0ul)) ||
            ((temp[i] == 0ul) && (set[j] == 0ul))))
        std::cout << "i = " << i << ", j = " << j << "\n";
      ++i;
      ++j;
    }
  }
}

BOOST_AUTO_TEST_CASE(left_shift) {
  // Fill bitset with random data
  std::size_t n = size * 0.25;
  GlobalFixture::world->srand(27);
  for (std::size_t i = 0; i < n; ++i)
    set.set(std::size_t(GlobalFixture::world->rand()) % size);

  // Check each bit shift from 0 to size
  for (std::size_t shift = 0; shift <= size; ++shift) {
    // Store shifted copy of bitset
    Bitset temp = set << shift;

    // Check that the head is filled with zeros
    std::size_t i = 0;
    std::size_t j = 0;
    while ((i < shift) && (i < size)) {
      BOOST_CHECK(temp[i] == 0ul);
      if (temp[i]) std::cout << "i = " << i << "\n";
      ++i;
    }
    // Check that the data has been shifted correctly
    while (i < size) {
      BOOST_CHECK(((temp[i] != 0ul) && (set[j] != 0ul)) ||
                  ((temp[i] == 0ul) && (set[j] == 0ul)));
      if (!(((temp[i] != 0ul) && (set[j] != 0ul)) ||
            ((temp[i] == 0ul) && (set[j] == 0ul))))
        std::cout << "i = " << i << ", j = " << j << "\n";
      ++i;
      ++j;
    }
  }
}

BOOST_AUTO_TEST_CASE(right_shift_assign) {
  // Fill bitset with random data
  std::size_t n = size * 0.25;
  GlobalFixture::world->srand(27);
  for (std::size_t i = 0; i < n; ++i)
    set.set(std::size_t(GlobalFixture::world->rand()) % size);

  // Check each bit shift from 0 to size
  for (std::size_t shift = 0; shift <= size; ++shift) {
    // Shift bitset data
    Bitset temp = set;
    temp >>= shift;

    // Check that the data has been shifted correctly
    std::size_t i = 0;
    std::size_t j = shift;
    while ((i < (size - shift)) && (j < size)) {
      BOOST_CHECK(((temp[i] != 0ul) && (set[j] != 0ul)) ||
                  ((temp[i] == 0ul) && (set[j] == 0ul)));
      if (!(((temp[i] != 0ul) && (set[j] != 0ul)) ||
            ((temp[i] == 0ul) && (set[j] == 0ul))))
        std::cout << "i = " << i << ", j = " << j << "\n";
      ++i;
      ++j;
    }
    // Check that the tail is filled with zeros
    while (i < size) {
      BOOST_CHECK(temp[i] == 0ul);
      if (temp[i]) std::cout << "i = " << i << "\n";
      ++i;
    }
  }
}

BOOST_AUTO_TEST_CASE(right_shift) {
  // Fill bitset with random data
  std::size_t n = size * 0.25;
  GlobalFixture::world->srand(27);
  for (std::size_t i = 0; i < n; ++i)
    set.set(std::size_t(GlobalFixture::world->rand()) % size);

  // Check each bit shift from 0 to size
  for (std::size_t shift = 0ul; shift <= size; ++shift) {
    // Store shifted copy of bitset
    Bitset temp = set >> shift;

    // Check that the data has been shifted correctly
    std::size_t i = 0;
    std::size_t j = shift;
    while ((i < (size - shift)) && (j < size)) {
      BOOST_CHECK(((temp[i] != 0ul) && (set[j] != 0ul)) ||
                  ((temp[i] == 0ul) && (set[j] == 0ul)));
      if (!(((temp[i] != 0ul) && (set[j] != 0ul)) ||
            ((temp[i] == 0ul) && (set[j] == 0ul))))
        std::cout << "i = " << i << ", j = " << j << "\n";
      ++i;
      ++j;
    }
    // Check that the tail is filled with zeros
    while (i < size) {
      BOOST_CHECK(temp[i] == 0ul);
      if (temp[i]) std::cout << "i = " << i << "\n";
      ++i;
    }
  }
}

BOOST_AUTO_TEST_CASE(bit_count) {
  // Fill bitset with random data
  std::size_t n = size * 0.25;
  GlobalFixture::world->srand(27);
  for (std::size_t i = 0; i < n; ++i)
    set.set(std::size_t(GlobalFixture::world->rand()) % size);

  // Count bits
  std::size_t count = 0ul;
  for (std::size_t i = 0ul; i < size; ++i)
    if (set[i]) ++count;

  BOOST_CHECK_EQUAL(set.count(), count);
}

BOOST_AUTO_TEST_CASE(operator_bool) {
  // Check that a bitset full of zeros returns false
  BOOST_CHECK_EQUAL(static_cast<bool>(set), false);

  // Fill bitset with random data
  std::size_t n = size * 0.25;
  GlobalFixture::world->srand(27);
  for (std::size_t i = 0; i < n; ++i)
    set.set(std::size_t(GlobalFixture::world->rand()) % size);

  // Check that a bitset with non-zero data returns true
  BOOST_CHECK_EQUAL(static_cast<bool>(set), true);
}

BOOST_AUTO_TEST_CASE(operator_not) {
  // Check that a bitset full of zeros returns true
  BOOST_CHECK_EQUAL(!set, true);

  // Fill bitset with random data
  std::size_t n = size * 0.25;
  GlobalFixture::world->srand(27);
  for (std::size_t i = 0; i < n; ++i)
    set.set(std::size_t(GlobalFixture::world->rand()) % size);

  // Check that a bitset with non-zero data returns false
  BOOST_CHECK_EQUAL(!set, false);
}

BOOST_AUTO_TEST_SUITE_END()