Browse Source

tictactoe: added method countCharsInCol

tictactoe
Tobias Krause 3 years ago
committed by Lorenz Hohmann
parent
commit
8c89d0edd6
  1. 5
      src/main/java/de/tims/tictactoe/ai/AIHard.java
  2. 17
      src/test/java/de/tims/tictactoe/ai/AIHardTest.java

5
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;
}
}

17
src/test/java/de/tims/tictactoe/ai/AIHardTest.java

@ -86,4 +86,21 @@ class AIHardTest {
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<Arguments> testCasesForCountCharsInCol() {
return Stream.of(Arguments.of("EmptyFieldReturns0",
new char[][] { {'-', '-', '-'}, {'-', '-', '-'}, {'-', '-', '-'} },
0, 'o', 0));
}
}
Loading…
Cancel
Save