From 645770c07c21ee5115a3c8afeb96ae4762eab46a Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Wed, 2 Feb 2022 15:37:41 +0100 Subject: [PATCH] 4gewinnt: finished checkButtons method --- src/main/java/de/tims/viergewinnt/ai/Logic.java | 6 +++++- .../java/de/tims/viergewinnt/ai/LogicTest.java | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/viergewinnt/ai/Logic.java b/src/main/java/de/tims/viergewinnt/ai/Logic.java index 5773da8..eaa9aca 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -87,7 +87,11 @@ public class Logic { } public boolean checkButtons() { - return true; + boolean res = false; + for(int i = 0; i < buttons.length; i++) { + res = buttons[i].isEnabled() | res; + } + return res; } JPanel contentPanel; diff --git a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java index c2f308a..9800775 100644 --- a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java +++ b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java @@ -227,7 +227,7 @@ class LogicTest { } @Test - void checkButtonsTest() { + void checkButtonsTestTrue() { testObj.create4gewinntGui(); boolean expectedResult = true; @@ -236,6 +236,19 @@ class LogicTest { assertEquals(expectedResult, realResult); } + @Test + void checkButtonsTestFalse() { + testObj.create4gewinntGui(); + boolean expectedResult = false; + for(int i = 0; i < testObj.buttons.length; i++) { + testObj.buttons[i].setEnabled(false); + } + + boolean realResult = testObj.checkButtons(); + + assertEquals(expectedResult, realResult); + } + private static Stream playfieldResults() { int[][] playfield1 = {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0},