summaryrefslogtreecommitdiff
path: root/tests/flag_set.cc
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-03-29 20:32:55 +0200
committerBardur Arantsson <bardur@scientician.net>2016-03-29 20:32:55 +0200
commitc8df88d8c61197d8f019efa0ba373ed14a28d914 (patch)
tree75335e7c9d0784ec4fa267c1a85f42e68100484c /tests/flag_set.cc
parent1a8a922f380a6401972f57beae602f3e8eca37e7 (diff)
Introduce new way of handling flags
Diffstat (limited to 'tests/flag_set.cc')
-rw-r--r--tests/flag_set.cc85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/flag_set.cc b/tests/flag_set.cc
new file mode 100644
index 00000000..125d8a81
--- /dev/null
+++ b/tests/flag_set.cc
@@ -0,0 +1,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));
+ });
+
+ });
+
+});