summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/flag_set.cc110
-rw-r--r--tests/grid.cc52
2 files changed, 162 insertions, 0 deletions
diff --git a/tests/flag_set.cc b/tests/flag_set.cc
new file mode 100644
index 00000000..fe1ad4a4
--- /dev/null
+++ b/tests/flag_set.cc
@@ -0,0 +1,110 @@
+#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));
+ });
+
+ 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));
+ });
+ });
+
+});
diff --git a/tests/grid.cc b/tests/grid.cc
new file mode 100644
index 00000000..ff618088
--- /dev/null
+++ b/tests/grid.cc
@@ -0,0 +1,52 @@
+#include "grid.hpp"
+#include <bandit/bandit.h>
+using namespace bandit;
+
+go_bandit([]() {
+ describe("grid<>", []() {
+
+ auto w0 = size_t { 123 };
+ auto h0 = size_t { 42 };
+
+ it("width(...) properly sets returned width", [&](){
+ // Setup
+ grid<int> g;
+ // Exercise
+ g.width(w0);
+ // Verify
+ AssertThat(g.width(), Equals(w0));
+ });
+
+ it("height(...) properly sets returned height", [&](){
+ // Setup
+ grid<int> g;
+ // Exercise
+ g.height(h0);
+ // Verify
+ AssertThat(g.height(), Equals(h0));
+ });
+
+ it("resize(w, h) properly sets returned width and height", [&](){
+ // Setup
+ grid<int> g;
+ // Exercise
+ g.resize(w0, h0);
+ // Verify
+ AssertThat(g.width(), Equals(w0));
+ AssertThat(g.height(), Equals(h0));
+ });
+
+ it("operator () can access ((w-1), (h-1)) element", [&](){
+ // Class with 'magic' default value
+ struct X { int magic = 1001; };
+ // Setup
+ grid<X> g;
+ g.resize(w0 + 1, h0 + 1);
+ // Exercise
+ auto x = g(w0, h0);
+ // Verify
+ AssertThat(x.magic, Equals(1001));
+ });
+
+ });
+});