From 4e425ff54b9913570e1fc9547b461088c945d1c3 Mon Sep 17 00:00:00 2001 From: Malte Schellhardt Date: Sun, 30 Jan 2022 14:15:56 +0100 Subject: [PATCH] tictactoe: added restriction for board sizes below three --- src/main/java/de/tims/tictactoe/GameLogic.java | 4 +++- src/test/java/de/tims/tictactoe/GameLogicTest.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/tims/tictactoe/GameLogic.java b/src/main/java/de/tims/tictactoe/GameLogic.java index 1e7d6a8..f63da53 100644 --- a/src/main/java/de/tims/tictactoe/GameLogic.java +++ b/src/main/java/de/tims/tictactoe/GameLogic.java @@ -5,6 +5,9 @@ public class GameLogic { private int[][] board; public GameLogic(int size) { + if (size < 3) { + size = 3; + } this.board = new int[size][size]; } @@ -13,7 +16,6 @@ public class GameLogic { } public int countFields() { - // TODO Auto-generated method stub return this.board[0].length * this.board.length; } diff --git a/src/test/java/de/tims/tictactoe/GameLogicTest.java b/src/test/java/de/tims/tictactoe/GameLogicTest.java index 0f0335b..f37fdb0 100644 --- a/src/test/java/de/tims/tictactoe/GameLogicTest.java +++ b/src/test/java/de/tims/tictactoe/GameLogicTest.java @@ -52,6 +52,8 @@ class GameLogicTest { private static Stream testCasesForCountPlayfields() { 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("4x4 board with 16 playfields", 4, 16), Arguments.of("5x5 board with 25 playfields", 5,25)