Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion exercises/practice/state-of-tic-tac-toe/.meta/Example.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ let gameState (board: Board) =
Error ConsecutiveMovesBySamePlayer
elif numNaughts > numCrosses then
Error WrongPlayerStarted
elif won 'X' board && won 'O' board then
elif (won 'X' board && numCrosses <> numNaughts + 1)
|| (won 'O' board && numCrosses <> numNaughts) then
Error MoveMadeAfterGameWasDone
elif won 'X' board || won 'O' board then
Ok Win
Expand Down
6 changes: 6 additions & 0 deletions exercises/practice/state-of-tic-tac-toe/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@ reimplements = "b1dc8b13-46c4-47db-a96d-aa90eedc4e8d"

[4801cda2-f5b7-4c36-8317-3cdd167ac22c]
description = "Invalid boards -> Invalid board: players kept playing after a win"

[5a84757a-fc86-4328-aec9-a5759e6ed35d]
description = "Invalid boards -> Invalid board: O kept playing after X wins"

[cf25543d-583a-4656-b9ab-f82dc00a4a02]
description = "Invalid boards -> Invalid board: X kept playing after O wins"
18 changes: 18 additions & 0 deletions exercises/practice/state-of-tic-tac-toe/StateOfTicTacToeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,21 @@ let ``Invalid board: players kept playing after a win`` () =
let expected: Result<EndGameState, GameError> = Error MoveMadeAfterGameWasDone
gameState board |> should equal expected

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Invalid board: O kept playing after X wins`` () =
let board =
array2D [ ['O'; 'O'; ' '];
['X'; 'X'; 'X'];
[' '; 'O'; ' '] ]
let expected: Result<EndGameState, GameError> = Error MoveMadeAfterGameWasDone
gameState board |> should equal expected

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Invalid board: X kept playing after O wins`` () =
let board =
array2D [ ['X'; 'X'; ' '];
['O'; 'O'; 'O'];
[' '; 'X'; 'X'] ]
let expected: Result<EndGameState, GameError> = Error MoveMadeAfterGameWasDone
gameState board |> should equal expected

4 changes: 4 additions & 0 deletions generators/Generators.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,10 @@ type KillerSudokuHelper() =
type StateOfTicTacToe() =
inherit ExerciseGenerator()

override this.RenderSut testCase =
let parameters = this.RenderSutParameters testCase |> String.concat " "
$"gameState %s{parameters}"

override _.PropertiesWithIdentifier _ = [ "board"; "expected" ]

override _.IdentifierTypeAnnotation(_, key, _) =
Expand Down
Loading