-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtictactoe_test.go
67 lines (63 loc) · 1.52 KB
/
tictactoe_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package tictactoe_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/thenativeweb/codingcircle/tictactoe"
)
func TestHasWon(t *testing.T) {
testCases := []struct {
name string
fields []tictactoe.Field
size int
hasWon bool
}{
{
name: "Returns false for an empty board.",
fields: []tictactoe.Field{},
size: 3,
hasWon: false,
},
{
name: "Returns false for a board with a single field.",
fields: []tictactoe.Field{{0, 0}},
size: 3,
hasWon: false,
},
{
name: "Returns true for a row on a 3x3 board.",
fields: []tictactoe.Field{{0, 0}, {0, 1}, {0, 2}},
size: 3,
hasWon: true,
},
{
name: "Returns true for a column on a 3x3 board.",
fields: []tictactoe.Field{{0, 0}, {1, 0}, {2, 0}},
size: 3,
hasWon: true,
},
{
name: "Returns true for the slash diagonal on a 3x3 board.",
fields: []tictactoe.Field{{0, 1}, {0, 2}, {1, 0}, {1, 1}, {2, 0}, {2, 2}},
size: 3,
hasWon: true,
},
{
name: "Returns true for the backslash diagonal on a 3x3 board.",
fields: []tictactoe.Field{{0, 0}, {0, 1}, {1, 1}, {1, 2}, {2, 0}, {2, 2}},
size: 3,
hasWon: true,
},
{
name: "Returns true for a row on a 4x4 board.",
fields: []tictactoe.Field{{0, 0}, {0, 1}, {0, 2}, {0, 3}},
size: 4,
hasWon: true,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
hasWon := tictactoe.HasWon(testCase.fields, testCase.size)
assert.Equal(t, testCase.hasWon, hasWon)
})
}
}