aboutsummaryrefslogtreecommitdiffstats
path: root/bingo/board_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'bingo/board_test.go')
-rw-r--r--bingo/board_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/bingo/board_test.go b/bingo/board_test.go
new file mode 100644
index 0000000..5df20ee
--- /dev/null
+++ b/bingo/board_test.go
@@ -0,0 +1,60 @@
+package bingo_test
+
+import (
+ "iter"
+ "testing"
+
+ "github.com/jpappel/bingo-factory/bingo"
+)
+
+func TestRows(t *testing.T) {
+ g := bingo.Game{}
+
+ testGame := func(size int, length int) {
+
+ g.Checked = make([]bool, size)
+
+ testGroup := func(name string, iter iter.Seq[[]bool]) {
+ for i := range size {
+ g.Checked[i] = false
+ }
+ for group := range iter {
+ if len(group) != length {
+ t.Logf("Mismatching %s length: %d != %d", name, length, len(group))
+ t.FailNow()
+ }
+
+ for i := range length {
+ if group[i] != false {
+ t.Errorf("Incorrect value in %s!\n", name)
+ }
+ }
+ }
+ for i := range size {
+ g.Checked[i] = true
+ }
+ for group := range iter {
+ if len(group) != length {
+ t.Logf("Mismatching %s length: %d != %d\n", name, length, len(group))
+ }
+
+ for i := range length {
+ if group[i] != true {
+ t.Errorf("Incorrect value in %s!\n", name)
+ }
+ }
+ }
+ }
+
+ testGroup("row", g.Rows(length))
+ testGroup("col", g.Cols(length))
+ testGroup("diag", g.Diags(length))
+
+ }
+
+ t.Log("Testing Square Games")
+ testGame(9, 3)
+ testGame(25, 5)
+ t.Log("Testing Non-Square Games")
+ testGame(22, 2)
+}