Browse Source

tictactoe: added restriction for board sizes below three

tictactoe
Malte Schellhardt 2 years ago
committed by Lorenz Hohmann
parent
commit
4e425ff54b
  1. 4
      src/main/java/de/tims/tictactoe/GameLogic.java
  2. 2
      src/test/java/de/tims/tictactoe/GameLogicTest.java

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

@ -5,6 +5,9 @@ public class GameLogic {
private int[][] board; private int[][] board;
public GameLogic(int size) { public GameLogic(int size) {
if (size < 3) {
size = 3;
}
this.board = new int[size][size]; this.board = new int[size][size];
} }
@ -13,7 +16,6 @@ public class GameLogic {
} }
public int countFields() { public int countFields() {
// TODO Auto-generated method stub
return this.board[0].length * this.board.length; return this.board[0].length * this.board.length;
} }

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

@ -52,6 +52,8 @@ class GameLogicTest {
private static Stream<Arguments> testCasesForCountPlayfields() { private static Stream<Arguments> testCasesForCountPlayfields() {
return Stream.of( return Stream.of(
Arguments.of("1x1 board with too few fields", 1, 9),
Arguments.of("2x2 board with too few fields", 2, 9),
Arguments.of("3x3 board with 9 playfields", 3, 9), Arguments.of("3x3 board with 9 playfields", 3, 9),
Arguments.of("4x4 board with 16 playfields", 4, 16), Arguments.of("4x4 board with 16 playfields", 4, 16),
Arguments.of("5x5 board with 25 playfields", 5,25) Arguments.of("5x5 board with 25 playfields", 5,25)

Loading…
Cancel
Save