Browse Source

tictactoe: added method countCharsInRow

tictactoe
Tobias Krause 3 years ago
committed by Lorenz Hohmann
parent
commit
ddf9aebb8f
  1. 4
      src/main/java/de/tims/tictactoe/ai/AIHard.java
  2. 23
      src/test/java/de/tims/tictactoe/ai/AIHardTest.java

4
src/main/java/de/tims/tictactoe/ai/AIHard.java

@ -55,4 +55,8 @@ public class AIHard implements TicTacToeAI {
gl.setField(row, col, AI_CHAR); gl.setField(row, col, AI_CHAR);
} }
} }
public int countCharsInRow(int index, char charToCount) {
return 0;
}
} }

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

@ -1,9 +1,15 @@
package de.tims.tictactoe.ai; package de.tims.tictactoe.ai;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
@ -59,5 +65,22 @@ class AIHardTest {
verify(gl, times(1)).setField(0, 2, realChar); verify(gl, times(1)).setField(0, 2, realChar);
} }
@ParameterizedTest
@MethodSource("testCasesForCountCharsInRow")
void countCharsInRowTest(String testName, char[][] board, int rowNum, char charToCount, int expectedResult) {
doReturn(board).when(gl).getBoard();
AIHard ai = new AIHard(gl);
int realResult = ai.countCharsInRow(rowNum, charToCount);
assertThat(realResult).describedAs(testName).isEqualTo(expectedResult);
}
private static Stream<Arguments> testCasesForCountCharsInRow() {
return Stream.of(Arguments.of("EmptyFieldReturns0",
new char[][] { {'-', '-', '-'}, {'-', '-', '-'}, {'-', '-', '-'} },
0, 'o', 0));
}
} }
Loading…
Cancel
Save