Skip to content

Commit

Permalink
ttgpcplayer: add basic test (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Apr 24, 2021
1 parent 2fb6c7f commit 96a8f8d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ttggame/ttgpcplayer/pc_player_engine_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ttgpcplayer

import (
"testing"

"github.com/gucio321/tic-tac-go/ttggame/ttgboard"
"github.com/gucio321/tic-tac-go/ttggame/ttgletter"
)

func Test_canWin(t *testing.T) {
w, h, c := 3, 3, 3
board := ttgboard.NewBoard(w, h, c)
board.SetIndexState(0, ttgletter.LetterX)
board.SetIndexState(2, ttgletter.LetterX)
if i, ok := canWin(board, ttgletter.LetterX); i != 1 || !ok {
t.Fatalf("canWin returned wrong values\n%s", board)
}

board.SetIndexState(1, ttgletter.LetterO)
if _, ok := canWin(board, ttgletter.LetterX); ok {
t.Fatalf("canWin returned true\n%s", board)
}
}

func Test_canWinTwoMoves(t *testing.T) {
w, h, c := 5, 5, 4
board := ttgboard.NewBoard(w, h, c)
board.SetIndexState(12, ttgletter.LetterX)
board.SetIndexState(13, ttgletter.LetterX)

i := canWinTwoMoves(board, ttgletter.LetterX)

if len(i) != 2 {
t.Fatalf("canWin returned wrong values\n%s", board)
}

if i[0] != 11 {
t.Fatalf("canWin returned wrong values\n%s", board)
}
}

0 comments on commit 96a8f8d

Please sign in to comment.