From a0add6efc0119bffbc1e24909ba1f228bb4f1f21 Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Wed, 5 Jan 2022 14:21:52 +0100 Subject: [PATCH] 4gewinnt: testForWin testmethod refactored --- .../java/de/tims/viergewinnt/ai/Logic.java | 2 +- .../de/tims/viergewinnt/ai/LogicTest.java | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/tims/viergewinnt/ai/Logic.java b/src/main/java/de/tims/viergewinnt/ai/Logic.java index d5a1f4c..dbb4924 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -2,6 +2,6 @@ package de.tims.viergewinnt.ai; public class Logic { public boolean testForWin(int[][] playfield, int player) { - return true; + return false; } } diff --git a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java index e56560e..010fcd6 100644 --- a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java +++ b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java @@ -2,8 +2,13 @@ package de.tims.viergewinnt.ai; import static org.junit.jupiter.api.Assertions.*; +import java.util.stream.Stream; + 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 LogicTest { @@ -14,14 +19,19 @@ class LogicTest { testObj = new Logic(); } - @Test - void testForWinTest() { - int[][] testField = new int[6][6]; - boolean expectedResult = false; + @ParameterizedTest(name = "[{index}] {0} Player {2} {3}") + @MethodSource("playfieldResults") + void testForWinTest(String testName, int[][] playfield, int player, boolean expectedResult) { - boolean realResult = testObj.testForWin(testField, 1); + boolean realResult = testObj.testForWin(playfield, player); assertEquals(expectedResult, realResult); } + + private static Stream playfieldResults() { + return Stream.of( + Arguments.of("emptyField", new int[6][6], 1, false) + ); + } }