From c8df88d8c61197d8f019efa0ba373ed14a28d914 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 29 Mar 2016 20:32:55 +0200 Subject: Introduce new way of handling flags --- tests/flag_set.cc | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 tests/flag_set.cc (limited to 'tests/flag_set.cc') 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 +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)); + }); + + }); + +}); -- cgit v1.2.3 From 145ea9e004c6014c790abb8d7b81f7f1547af3b9 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Change flag_set bool conversion to 'explicit' --- tests/flag_set.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/flag_set.cc') diff --git a/tests/flag_set.cc b/tests/flag_set.cc index 125d8a81..3abd505d 100644 --- a/tests/flag_set.cc +++ b/tests/flag_set.cc @@ -45,7 +45,7 @@ go_bandit([]() { // Setup fs_t fs = fs_t(); // Exercise - bool result = fs; + auto result = bool(fs); // Verify AssertThat(result, Equals(false)); }); @@ -54,7 +54,7 @@ go_bandit([]() { // Setup fs_t fs = fs_t::make(1, 3); // Exercise - bool result = fs; + auto result = bool(fs); // Verify AssertThat(result, Equals(true)); }); -- cgit v1.2.3 From 117c211cf7ca94914eef75aa1c1912cd5d6de2ec Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 21 Jun 2016 06:05:58 +0200 Subject: Fix bug in flag_set '==' operator --- tests/flag_set.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/flag_set.cc') diff --git a/tests/flag_set.cc b/tests/flag_set.cc index 3abd505d..05418a05 100644 --- a/tests/flag_set.cc +++ b/tests/flag_set.cc @@ -59,6 +59,16 @@ go_bandit([]() { 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); -- cgit v1.2.3 From 073ad3584fbf781ce10bef61ad4ff38850282f47 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 21 Jun 2016 13:37:02 +0200 Subject: Rework TR{1,2,3,4,5}_* flags to flag_set<> --- tests/flag_set.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/flag_set.cc') diff --git a/tests/flag_set.cc b/tests/flag_set.cc index 05418a05..fe1ad4a4 100644 --- a/tests/flag_set.cc +++ b/tests/flag_set.cc @@ -90,6 +90,21 @@ go_bandit([]() { AssertThat(result[1], Equals(8UL)); }); + it("make_bit(5) should set the 5th bit in the 1st tier", [&] { + // Exercise + fs_t result = fs_t::make_bit(5); + // Verify + AssertThat(result[0], Equals(32L)); + AssertThat(result[1], Equals(0L)); + }); + + it("make_bit(37) should set the 5th bit in the 2nd tier", [&] { + // Exercise + fs_t result = fs_t::make_bit(37); + // Verify + AssertThat(result[0], Equals(0L)); + AssertThat(result[1], Equals(32L)); + }); }); }); -- cgit v1.2.3