Skip to content

Commit a38f5bc

Browse files
authored
[state-of-tic-tac-toe] sync tests (#3160)
Closes #3159
1 parent 2260ace commit a38f5bc

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

exercises/practice/state-of-tic-tac-toe/.meta/example.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ func StateOfTicTacToe(board []string) (State, error) {
4848
}
4949
}
5050

51+
if xWin > 0 && xCount == oCount {
52+
return "", errors.New("impossible board: game should have ended after the game was won")
53+
}
54+
if oWin > 0 && xCount != oCount {
55+
return "", errors.New("impossible board: game should have ended after the game was won")
56+
}
57+
5158
if xWin > 0 || oWin > 0 {
5259
return Win, nil
5360
}

exercises/practice/state-of-tic-tac-toe/.meta/tests.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,9 @@ reimplements = "b1dc8b13-46c4-47db-a96d-aa90eedc4e8d"
9999

100100
[4801cda2-f5b7-4c36-8317-3cdd167ac22c]
101101
description = "Invalid boards -> Invalid board: players kept playing after a win"
102+
103+
[5a84757a-fc86-4328-aec9-a5759e6ed35d]
104+
description = "Invalid boards -> Invalid board: O kept playing after X wins"
105+
106+
[cf25543d-583a-4656-b9ab-f82dc00a4a02]
107+
description = "Invalid boards -> Invalid board: X kept playing after O wins"

exercises/practice/state-of-tic-tac-toe/cases_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package stateoftictactoe
33
// This is an auto-generated file. Do not change it manually. Run the generator to update the file.
44
// See https://github.com/exercism/go#synchronizing-tests-and-instructions
55
// Source: exercism/problem-specifications
6-
// Commit: 25c2ae5 build(deps): bump fast-uri from 3.1.0 to 3.1.2 (#2653)
6+
// Commit: 0682194 state-of-tic-tac-toe: Add test cases for playing after a win (#2667)
77

88
type testCase struct {
99
description string
@@ -175,4 +175,16 @@ var testCases = []testCase{
175175
expected: "",
176176
wantErr: true,
177177
},
178+
{
179+
description: "Invalid board: O kept playing after X wins",
180+
board: []string{"OO ", "XXX", " O "},
181+
expected: "",
182+
wantErr: true,
183+
},
184+
{
185+
description: "Invalid board: X kept playing after O wins",
186+
board: []string{"XX ", "OOO", " XX"},
187+
expected: "",
188+
wantErr: true,
189+
},
178190
}

exercises/practice/state-of-tic-tac-toe/state_of_tic_tac_toe_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func TestStateOfTicTacToe(t *testing.T) {
1010
result, err := StateOfTicTacToe(c.board)
1111
switch {
1212
case c.wantErr && err == nil:
13-
t.Fatalf("\n Board: %#v \n Expected error but got nil", c.board)
13+
t.Fatalf("\n Board: %#v \n Expected error but got %v, nil", c.board, result)
1414

1515
case !c.wantErr && err != nil:
1616
t.Fatalf("\n Board: %#v \n Expected no errors but got error: %q", c.board, err)

0 commit comments

Comments
 (0)