File tree Expand file tree Collapse file tree
exercises/practice/state-of-tic-tac-toe Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -99,3 +99,9 @@ reimplements = "b1dc8b13-46c4-47db-a96d-aa90eedc4e8d"
9999
100100[4801cda2-f5b7-4c36-8317-3cdd167ac22c ]
101101description = " 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"
Original file line number Diff line number Diff 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+
Original file line number Diff line number Diff line change @@ -2145,6 +2145,10 @@ type KillerSudokuHelper() =
21452145type 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 , _ ) =
You can’t perform that action at this time.
0 commit comments