From 3e99d48ff0ba82c1cfd0cb557e7f1dac82e49508 Mon Sep 17 00:00:00 2001 From: Malte Schellhardt Date: Thu, 10 Feb 2022 20:03:33 +0100 Subject: [PATCH] tictactoe: added test case to check if player 1 has won in column 1 --- src/main/java/de/tims/tictactoe/GameLogic.java | 6 +++--- src/test/java/de/tims/tictactoe/GameLogicTest.java | 4 ++++ 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 d9a59ab..2a71983 100644 --- a/src/main/java/de/tims/tictactoe/GameLogic.java +++ b/src/main/java/de/tims/tictactoe/GameLogic.java @@ -48,14 +48,14 @@ public class GameLogic { // check columns for (int i = 0; i < this.board.length; i++) { for (int j = 0; j < this.board[0].length; j++) { - if(board[i][j] == player) countFields++; + if(board[i][j] == player) countFields++; } } if(countFields == this.board.length) finished = true; // check rows - for (int i = 0; i < this.board.length; i++) { - for (int j = 0; j < this.board[0].length; j++) { + for (int i = 0; i < this.board[0].length; i++) { + for (int j = 0; j < this.board.length; j++) { if(board[j][i] == player) countFields++; } } diff --git a/src/test/java/de/tims/tictactoe/GameLogicTest.java b/src/test/java/de/tims/tictactoe/GameLogicTest.java index e22d0de..e2ec822 100644 --- a/src/test/java/de/tims/tictactoe/GameLogicTest.java +++ b/src/test/java/de/tims/tictactoe/GameLogicTest.java @@ -138,6 +138,10 @@ class GameLogicTest { {{'x', '-', '-'}, {'x', '-', '-'}, {'x', '-', '-'}}), + Arguments.of("check win in column 1 for player 1", 'x', true, new char[][] + {{'-', 'x', '-'}, + {'-', 'x', '-'}, + {'-', 'x', '-'}}), Arguments.of("check win in column 0 for player 2", 'o', true, new char[][] {{'o', '-', '-'}, {'o', '-', '-'},