Browse Source

tictactoe: added test cases for fieldIsEmpty method and created constructor with gameboard as parameter

tictactoe
Malte Schellhardt 3 years ago
committed by Lorenz Hohmann
parent
commit
58f7647ce8
  1. 12
      src/main/java/de/tims/tictactoe/GameLogic.java
  2. 11
      src/test/java/de/tims/tictactoe/GameLogicTest.java

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

@ -1,5 +1,7 @@
package de.tims.tictactoe;
import java.util.Arrays;
public class GameLogic {
private char[][] board;
@ -18,6 +20,10 @@ public class GameLogic {
}
}
public GameLogic(char[][] board) {
this.board = board;
}
public char[][] getBoard() {
return this.board;
}
@ -31,8 +37,12 @@ public class GameLogic {
}
public boolean fieldIsEmpty(int column, int row) {
// TODO Auto-generated method stub
if (this.board[column][row] == emptyField) {
System.out.println(Arrays.toString(this.board));
return true;
} else {
return false;
}
}
}

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

@ -63,7 +63,8 @@ class GameLogicTest {
@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);
GameLogic game = new GameLogic(board);
boolean realResult = game.fieldIsEmpty(columnToCheck, rowToCheck);
assertEquals(expectedResult, realResult);
}
@ -95,6 +96,14 @@ class GameLogicTest {
return Stream.of(
Arguments.of("check an empty field", 0, 0, true, new char[][]
{{'-', '-', '-'},
{'-', '-', '-'},
{'-', '-', '-'}}),
Arguments.of("check a field set by player 1", 0, 0, false, new char[][]
{{'x', '-', '-'},
{'-', '-', '-'},
{'-', '-', '-'}}),
Arguments.of("check a field set by player 2", 0, 0, false, new char[][]
{{'o', '-', '-'},
{'-', '-', '-'},
{'-', '-', '-'}})
);

Loading…
Cancel
Save