Skip to content

Commit f0ff1f1

Browse files
authored
Merge pull request #123 from gucio321/game
ttgpcplayer: add basic test (#112)
2 parents 20dc74c + 2b4a2b6 commit f0ff1f1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ttgpcplayer
2+
3+
import (
4+
"testing"
5+
6+
"github.com/gucio321/tic-tac-go/ttggame/ttgboard"
7+
"github.com/gucio321/tic-tac-go/ttggame/ttgletter"
8+
)
9+
10+
func Test_canWin(t *testing.T) {
11+
w, h, c := 3, 3, 3
12+
board := ttgboard.NewBoard(w, h, c)
13+
board.SetIndexState(0, ttgletter.LetterX)
14+
board.SetIndexState(2, ttgletter.LetterX)
15+
16+
if i, ok := canWin(board, ttgletter.LetterX); i != 1 || !ok {
17+
t.Fatalf("canWin returned wrong values\n%s", board)
18+
}
19+
20+
board.SetIndexState(1, ttgletter.LetterO)
21+
22+
if _, ok := canWin(board, ttgletter.LetterX); ok {
23+
t.Fatalf("canWin returned true\n%s", board)
24+
}
25+
}
26+
27+
func Test_canWinTwoMoves(t *testing.T) {
28+
w, h, c := 5, 5, 4
29+
board := ttgboard.NewBoard(w, h, c)
30+
board.SetIndexState(12, ttgletter.LetterX)
31+
board.SetIndexState(13, ttgletter.LetterX)
32+
33+
i := canWinTwoMoves(board, ttgletter.LetterX)
34+
35+
if len(i) != 1 {
36+
t.Fatalf("canWin returned wrong values\n%s", board)
37+
}
38+
39+
if i[0] != 11 {
40+
t.Fatalf("canWin returned wrong values\n%s", board)
41+
}
42+
}

0 commit comments

Comments
 (0)