diff --git a/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml b/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml index 8fc25e21..5f574b2a 100644 --- a/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml +++ b/exercises/practice/state-of-tic-tac-toe/.meta/tests.toml @@ -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" diff --git a/exercises/practice/state-of-tic-tac-toe/example/state_of_tic_tac_toe.d b/exercises/practice/state-of-tic-tac-toe/example/state_of_tic_tac_toe.d index 7a335f18..d3f121cd 100644 --- a/exercises/practice/state-of-tic-tac-toe/example/state_of_tic_tac_toe.d +++ b/exercises/practice/state-of-tic-tac-toe/example/state_of_tic_tac_toe.d @@ -51,6 +51,16 @@ pure State gamestate(immutable string[] board) throw new Exception("Impossible board: game should have ended after the game was won"); } + if (win_x && count_o == count_x) + { + throw new Exception("Impossible board: O kept playing after X wins"); + } + + if (win_o && count_x > count_o) + { + throw new Exception("Impossible board: X kept playing after O wins"); + } + return State.win; } diff --git a/exercises/practice/state-of-tic-tac-toe/source/state_of_tic_tac_toe.d b/exercises/practice/state-of-tic-tac-toe/source/state_of_tic_tac_toe.d index 7fa19375..3c1a3eda 100644 --- a/exercises/practice/state-of-tic-tac-toe/source/state_of_tic_tac_toe.d +++ b/exercises/practice/state-of-tic-tac-toe/source/state_of_tic_tac_toe.d @@ -288,5 +288,25 @@ unittest ]; assertThrown(gamestate(board)); } + + // Invalid boards-Invalid board: O kept playing after X wins + { + immutable string[] board = [ + "OO ", + "XXX", + " O ", + ]; + assertThrown(gamestate(board)); + } + + // Invalid boards-Invalid board: X kept playing after O wins + { + immutable string[] board = [ + "XX ", + "OOO", + " XX", + ]; + assertThrown(gamestate(board)); + } } }