summaryrefslogtreecommitdiff
path: root/tests/flag_set.cc
blob: 05418a05f11d52e967456dd29a4019aa1e127a07 (plain)
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
#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
			auto result = bool(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
			auto result = bool(fs);
			// Verify
			AssertThat(result, Equals(true));
		});

		it("== operator should compare equals as equals", [&] {
			// Setup
			fs_t fs1 = fs_t::make(1, 3);
			fs_t fs2 = fs_t::make(1, 3);
			// Exercise
			auto result = (fs1 == fs2);
			// 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));
		});

	});

});