From f81871b1807c07e6c79c5f71458bb4b26eb21fa7 Mon Sep 17 00:00:00 2001 From: Malte Schellhardt Date: Wed, 9 Feb 2022 17:55:52 +0100 Subject: [PATCH] tictactoe: fixed previous checkForWin test cases --- src/main/java/de/tims/tictactoe/GameLogic.java | 7 +++---- src/test/java/de/tims/tictactoe/GameLogicTest.java | 10 +++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/tims/tictactoe/GameLogic.java b/src/main/java/de/tims/tictactoe/GameLogic.java index 6fc6f9f..d9a59ab 100644 --- a/src/main/java/de/tims/tictactoe/GameLogic.java +++ b/src/main/java/de/tims/tictactoe/GameLogic.java @@ -54,10 +54,9 @@ public class GameLogic { if(countFields == this.board.length) finished = true; // check rows - for (int i = 0; i < this.board[0].length; i++) { - for (int j = 0; j < this.board.length; j++) { - if(board[i][j] == player) countFields++; - break; + for (int i = 0; i < this.board.length; i++) { + for (int j = 0; j < this.board[0].length; j++) { + if(board[j][i] == player) countFields++; } } if(countFields == this.board.length) finished = true; diff --git a/src/test/java/de/tims/tictactoe/GameLogicTest.java b/src/test/java/de/tims/tictactoe/GameLogicTest.java index 223fd9c..1dcc42b 100644 --- a/src/test/java/de/tims/tictactoe/GameLogicTest.java +++ b/src/test/java/de/tims/tictactoe/GameLogicTest.java @@ -148,12 +148,12 @@ class GameLogicTest { {'-', '-', '-'}}), Arguments.of("check win in row 0 for player 1", 'x', true, new char[][] {{'x', 'x', 'x'}, - {'o', '-', '-'}, - {'-', '-', 'o'}}), - Arguments.of("check win in row 0 for player 2", 'x', true, new char[][] + {'-', '-', '-'}, + {'-', '-', '-'}}), + Arguments.of("check win in row 0 for player 2", 'o', true, new char[][] {{'o', 'o', 'o'}, - {'x', 'o', '-'}, - {'-', '-', 'x'}}) + {'-', '-', '-'}, + {'-', '-', '-'}}) ); }