Skip to content

Commit 4884cb3

Browse files
committed
Sync state-of-tic-tac-toe tests
1 parent 42f3989 commit 4884cb3

4 files changed

Lines changed: 30 additions & 1 deletion

File tree

exercises/practice/state-of-tic-tac-toe/.meta/Example.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ let gameState (board: Board) =
3737
Error ConsecutiveMovesBySamePlayer
3838
elif numNaughts > numCrosses then
3939
Error WrongPlayerStarted
40-
elif won 'X' board && won 'O' board then
40+
elif (won 'X' board && numCrosses <> numNaughts + 1)
41+
|| (won 'O' board && numCrosses <> numNaughts) then
4142
Error MoveMadeAfterGameWasDone
4243
elif won 'X' board || won 'O' board then
4344
Ok Win

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/StateOfTicTacToeTests.fs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,21 @@ let ``Invalid board: players kept playing after a win`` () =
248248
let expected: Result<EndGameState, GameError> = Error MoveMadeAfterGameWasDone
249249
gameState board |> should equal expected
250250

251+
[<Fact(Skip = "Remove this Skip property to run this test")>]
252+
let ``Invalid board: O kept playing after X wins`` () =
253+
let board =
254+
array2D [ ['O'; 'O'; ' '];
255+
['X'; 'X'; 'X'];
256+
[' '; 'O'; ' '] ]
257+
let expected: Result<EndGameState, GameError> = Error MoveMadeAfterGameWasDone
258+
gameState board |> should equal expected
259+
260+
[<Fact(Skip = "Remove this Skip property to run this test")>]
261+
let ``Invalid board: X kept playing after O wins`` () =
262+
let board =
263+
array2D [ ['X'; 'X'; ' '];
264+
['O'; 'O'; 'O'];
265+
[' '; 'X'; 'X'] ]
266+
let expected: Result<EndGameState, GameError> = Error MoveMadeAfterGameWasDone
267+
gameState board |> should equal expected
268+

generators/Generators.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,10 @@ type KillerSudokuHelper() =
21452145
type StateOfTicTacToe() =
21462146
inherit ExerciseGenerator()
21472147

2148+
override this.RenderSut testCase =
2149+
let parameters = this.RenderSutParameters testCase |> String.concat " "
2150+
$"gameState %s{parameters}"
2151+
21482152
override _.PropertiesWithIdentifier _ = [ "board"; "expected" ]
21492153

21502154
override _.IdentifierTypeAnnotation(_, key, _) =

0 commit comments

Comments
 (0)