From 525754409a68925405fd9c56f185eef1898a2fad Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Mon, 31 Jan 2022 14:45:06 +0100 Subject: [PATCH] tictactoe: added method countCharsInDiag --- .../java/de/tims/tictactoe/ai/AIHard.java | 4 ++++ .../java/de/tims/tictactoe/ai/AIHardTest.java | 21 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/tictactoe/ai/AIHard.java b/src/main/java/de/tims/tictactoe/ai/AIHard.java index 56ff489..df3c16a 100644 --- a/src/main/java/de/tims/tictactoe/ai/AIHard.java +++ b/src/main/java/de/tims/tictactoe/ai/AIHard.java @@ -77,4 +77,8 @@ public class AIHard implements TicTacToeAI { return count; } + + public int countCharsInDiag(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 f764772..5fdd8d6 100644 --- a/src/test/java/de/tims/tictactoe/ai/AIHardTest.java +++ b/src/test/java/de/tims/tictactoe/ai/AIHardTest.java @@ -88,11 +88,11 @@ class AIHardTest { @ParameterizedTest @MethodSource("testCasesForCountCharsInCol") - void countCharsInColTest(String testName, char[][] board, int rowNum, char charToCount, int expectedResult) { + void countCharsInColTest(String testName, char[][] board, int colNum, char charToCount, int expectedResult) { doReturn(board).when(gl).getBoard(); AIHard ai = new AIHard(gl); - int realResult = ai.countCharsInCol(rowNum, charToCount); + int realResult = ai.countCharsInCol(colNum, charToCount); assertThat(realResult).describedAs(testName).isEqualTo(expectedResult); } @@ -105,5 +105,22 @@ class AIHardTest { new char[][] { {'-', '-', '-'}, {'o', 'o', '-'}, {'-', '-', '-'} }, 1, 'o', 1)); } + + @ParameterizedTest + @MethodSource("testCasesForCountCharsInDiag") + void countCharsInDiagTest(String testName, char[][] board, int diagNum, char charToCount, int expectedResult) { + doReturn(board).when(gl).getBoard(); + + AIHard ai = new AIHard(gl); + int realResult = ai.countCharsInDiag(diagNum, charToCount); + + assertThat(realResult).describedAs(testName).isEqualTo(expectedResult); + } + + private static Stream testCasesForCountCharsInDiag() { + return Stream.of(Arguments.of("EmptyFieldReturns0", + new char[][] { {'-', '-', '-'}, {'-', '-', '-'}, {'-', '-', '-'} }, + 0, 'o', 0)); + } }