From eec2f540a5e72c2907e4c3f68e713ccfb5256b90 Mon Sep 17 00:00:00 2001 From: Malte Schellhardt Date: Thu, 10 Feb 2022 23:14:32 +0100 Subject: [PATCH] tictactoe: added test case to check if player 1 has won in row 0 with full board --- src/main/java/de/tims/tictactoe/GameLogic.java | 4 ++-- src/test/java/de/tims/tictactoe/GameLogicTest.java | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/tims/tictactoe/GameLogic.java b/src/main/java/de/tims/tictactoe/GameLogic.java index 7891235..6fed5b6 100644 --- a/src/main/java/de/tims/tictactoe/GameLogic.java +++ b/src/main/java/de/tims/tictactoe/GameLogic.java @@ -48,7 +48,6 @@ public class GameLogic { // check columns for (int i = 0; i < this.board.length; i++) { for (int j = 0; j < this.board[0].length; j++) { - System.out.println(j + ", " + i); if(board[j][i] == player) countFields++; } if(countFields == this.board.length) return finished = true; @@ -61,8 +60,9 @@ public class GameLogic { for (int j = 0; j < this.board.length; j++) { if(board[i][j] == player) countFields++; } + if(countFields == this.board.length) return finished = true; + countFields = 0; } - if(countFields == this.board.length) finished = true; return finished; } diff --git a/src/test/java/de/tims/tictactoe/GameLogicTest.java b/src/test/java/de/tims/tictactoe/GameLogicTest.java index 00914d4..70123df 100644 --- a/src/test/java/de/tims/tictactoe/GameLogicTest.java +++ b/src/test/java/de/tims/tictactoe/GameLogicTest.java @@ -181,7 +181,11 @@ class GameLogicTest { Arguments.of("check win in column 2 for player 2 with full board", 'o', true, new char[][] {{'x', 'o', 'o'}, {'x', 'x', 'o'}, - {'o', 'o', 'o'}}) + {'o', 'o', 'o'}}), + Arguments.of("check win in row 0 for player 1 with full board", 'x', true, new char[][] + {{'x', 'x', 'x'}, + {'x', 'o', 'o'}, + {'o', 'o', 'x'}}) ); }