Browse Source

tictactoe: added method to check if field is not set

tictactoe
Malte Schellhardt 3 years ago
committed by Lorenz Hohmann
parent
commit
cc16fd3389
  1. 6
      src/main/java/de/tims/tictactoe/GameLogic.java
  2. 17
      src/test/java/de/tims/tictactoe/GameLogicTest.java

6
src/main/java/de/tims/tictactoe/GameLogic.java

@ -3,6 +3,7 @@ package de.tims.tictactoe;
public class GameLogic {
private char[][] board;
private final char emptyField = '-';
public GameLogic(int size) {
if (size < 3) {
@ -29,4 +30,9 @@ public class GameLogic {
this.board[column][row] = player;
}
public boolean fieldIsEmpty(int column, int row) {
// TODO Auto-generated method stub
return true;
}
}

17
src/test/java/de/tims/tictactoe/GameLogicTest.java

@ -60,6 +60,14 @@ class GameLogicTest {
assertArrayEquals(expectedResult, realResult);
}
@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("testCasesForCheckEmptyField")
void fieldIsEmptyTest(String testName, int columnToCheck, int rowToCheck, boolean expectedResult, char[][] board) {
boolean realResult = this.game.fieldIsEmpty(columnToCheck, rowToCheck);
assertEquals(expectedResult, realResult);
}
private static Stream<Arguments> testCasesForCountPlayfields() {
return Stream.of(
Arguments.of("1x1 board with too few fields", 1, 9),
@ -83,4 +91,13 @@ class GameLogicTest {
);
}
private static Stream<Arguments> testCasesForCheckEmptyField() {
return Stream.of(
Arguments.of("check an empty field", 0, 0, true, new char[][]
{{'-', '-', '-'},
{'-', '-', '-'},
{'-', '-', '-'}})
);
}
}
Loading…
Cancel
Save