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