From 8c89d0edd650963f8a89fb210c1f3ce5c985e23d Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Mon, 31 Jan 2022 14:13:28 +0100 Subject: [PATCH] tictactoe: added method countCharsInCol --- src/main/java/de/tims/tictactoe/ai/AIHard.java | 5 +++++ .../java/de/tims/tictactoe/ai/AIHardTest.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/main/java/de/tims/tictactoe/ai/AIHard.java b/src/main/java/de/tims/tictactoe/ai/AIHard.java index 48e7d1b..ac70681 100644 --- a/src/main/java/de/tims/tictactoe/ai/AIHard.java +++ b/src/main/java/de/tims/tictactoe/ai/AIHard.java @@ -59,10 +59,15 @@ public class AIHard implements TicTacToeAI { public int countCharsInRow(int index, char charToCount) { int count = 0; char[][] board = gl.getBoard(); + for (int i = 0; i < BOARD_SIZE; i++) { count += (board[index][i] == charToCount) ? 1 : 0; } return count; } + + public int countCharsInCol(int index, char charToCount) { + return 0; + } } diff --git a/src/test/java/de/tims/tictactoe/ai/AIHardTest.java b/src/test/java/de/tims/tictactoe/ai/AIHardTest.java index a35614b..76a81f5 100644 --- a/src/test/java/de/tims/tictactoe/ai/AIHardTest.java +++ b/src/test/java/de/tims/tictactoe/ai/AIHardTest.java @@ -85,5 +85,22 @@ class AIHardTest { new char[][] { {'-', '-', '-'}, {'o', 'o', '-'}, {'-', '-', '-'} }, 1, 'o', 2)); } + + @ParameterizedTest + @MethodSource("testCasesForCountCharsInCol") + void countCharsInColTest(String testName, char[][] board, int rowNum, char charToCount, int expectedResult) { + doReturn(board).when(gl).getBoard(); + + AIHard ai = new AIHard(gl); + int realResult = ai.countCharsInCol(rowNum, charToCount); + + assertThat(realResult).describedAs(testName).isEqualTo(expectedResult); + } + + private static Stream testCasesForCountCharsInCol() { + return Stream.of(Arguments.of("EmptyFieldReturns0", + new char[][] { {'-', '-', '-'}, {'-', '-', '-'}, {'-', '-', '-'} }, + 0, 'o', 0)); + } }