Skip to content

Commit

Permalink
test: Added tests for wordsearch module
Browse files Browse the repository at this point in the history
  • Loading branch information
cheatsnake committed Aug 6, 2022
1 parent 7d02e5c commit 000ab74
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pkg/wordsearch/core_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package wordsearch

import (
"path/filepath"
"testing"

"github.com/cheatsnake/shadify/pkg/assists"
)

func TestGenerateSuccess(t *testing.T) {
wordsDB, _ = assists.ReadFileLineByLine(filepath.Join("..", "..", "data", "nouns.txt"))
testValues := [][]int{{8, 8}, {5, 5}, {16, 16}, {20, 12}, {12, 20}, {5, 20}, {20, 5}}

for _, tv := range testValues {
result, _ := Generate(tv[0], tv[1])

if result.Width != tv[0] ||
result.Height != tv[1] ||
len(result.Grid)*len(result.Grid[0]) != tv[0]*tv[1] {
t.Errorf(
"Generate(%d, %d) FAILED. Expected result.Width = %d, result.Height = %d and total ceils = %d, but got %d, %d, %d",
tv[0], tv[1], tv[0], tv[1], tv[0]*tv[1], result.Width, result.Height, len(result.Grid)*len(result.Grid[0]))
} else {
t.Logf("Generate(%d, %d) PASSED", tv[0], tv[1])
}
}
}

func TestGenerateFail(t *testing.T) {
testValues := [][]int{{4, 8}, {21, 8}, {8, 4}, {8, 21}, {17, 16}}

for _, tv := range testValues {
_, err := Generate(tv[0], tv[1])

if err == nil {
t.Errorf("Generate(%d, %d) FAILED. Expected error != nil, but got nil", tv[0], tv[1])
} else {
t.Logf("Generate(%d, %d) -> '%+v', PASSED", tv[0], tv[1], err)
}
}
}

0 comments on commit 000ab74

Please sign in to comment.