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
|
#include "flag_set.hpp"
#include <bandit/bandit.h>
using namespace bandit;
//
// Tests
//
go_bandit([]() {
describe("flag_set", []() {
// Convenience typedef
typedef flag_set<2> fs_t;
it("make function should handle tier=0, index=31 properly", [&] {
// Setup
fs_t fs = fs_t::make(0, 31);
// Exercise
auto result = fs;
// Verify
AssertThat(result[0], Equals(2147483648UL));
AssertThat(result[1], Equals(0UL));
});
it("make function should handle tier=1, index=31 properly", [&] {
// Setup
fs_t fs = fs_t::make(1, 31);
// Exercise
auto result = fs;
// Verify
AssertThat(result[0], Equals(0UL));
AssertThat(result[1], Equals(2147483648UL));
});
it("make function should respect the tier and index", [&] {
// Exercise
fs_t fs = fs_t::make(1, 7);
// Verify
AssertThat(fs[0], Equals(0UL));
AssertThat(fs[1], Equals(128UL));
});
it("bool conversion should return false for zero flags", [&] {
// Setup
fs_t fs = fs_t();
// Exercise
bool result = fs;
// Verify
AssertThat(result, Equals(false));
});
it("bool conversion should return true for non-zero flags", [&] {
// Setup
fs_t fs = fs_t::make(1, 3);
// Exercise
bool result = fs;
// Verify
AssertThat(result, Equals(true));
});
it("| operator should respect the tier and index", [&] {
// Setup
fs_t fs1 = fs_t::make(0, 31);
fs_t fs2 = fs_t::make(1, 3);
// Exercise
fs_t fs = fs1 | fs2;
// Verify
AssertThat(fs[0], Equals(2147483648UL));
AssertThat(fs[1], Equals(8UL));
});
it("& operator should respect the tier and index", [&] {
// Setup
fs_t fs = fs_t::make(0, 31) | fs_t::make(1, 3);
// Exercise
fs_t result = fs & fs;
// Verify
AssertThat(result[0], Equals(2147483648UL));
AssertThat(result[1], Equals(8UL));
});
});
});
|