From edbbefc7ff420948a721896dff16b2fed6231302 Mon Sep 17 00:00:00 2001 From: Malte Schellhardt Date: Sun, 30 Jan 2022 14:08:26 +0100 Subject: [PATCH] tictactoe: fixed fieldCountTest. Now works with different playfield sizes --- .../java/de/tims/tictactoe/GameLogic.java | 2 +- .../java/de/tims/tictactoe/GameLogicTest.java | 31 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/tims/tictactoe/GameLogic.java b/src/main/java/de/tims/tictactoe/GameLogic.java index a449fdb..1e7d6a8 100644 --- a/src/main/java/de/tims/tictactoe/GameLogic.java +++ b/src/main/java/de/tims/tictactoe/GameLogic.java @@ -14,7 +14,7 @@ public class GameLogic { public int countFields() { // TODO Auto-generated method stub - return 9; + 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 d6d7176..0f0335b 100644 --- a/src/test/java/de/tims/tictactoe/GameLogicTest.java +++ b/src/test/java/de/tims/tictactoe/GameLogicTest.java @@ -1,10 +1,16 @@ package de.tims.tictactoe; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.stream.Stream; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; class GameLogicTest { @@ -35,12 +41,21 @@ class GameLogicTest { assertArrayEquals(expectedResult, realResult); } - @Test - void fieldCountTest() { - int expectedResult = 9; - int realResult = game.countFields(); - - assertEquals(expectedResult, realResult); - } + @ParameterizedTest(name = "[{index}] {0} -> {1}") + @MethodSource("testCasesForCountPlayfields") + void fieldCountTest(String testName, int size, int expectedResult) { + GameLogic game = new GameLogic(size); + int realResult = game.countFields(); + + assertEquals(expectedResult, realResult); + } + + private static Stream testCasesForCountPlayfields() { + return Stream.of( + 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) + ); + } }