From ac9183ea27b58936f7cf095cdae19cd901a75646 Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Fri, 14 Jan 2022 14:18:53 +0100 Subject: [PATCH] overload getState() in Matchfield --- src/main/java/de/tims/fleetstorm/ai/Logic.java | 1 - .../de/tims/fleetstorm/matchfield/Matchfield.java | 4 ++++ src/test/java/de/tims/fleetstorm/ai/LogicTest.java | 1 + .../matchfield/MatchfieldCreationTest.java | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/tims/fleetstorm/ai/Logic.java b/src/main/java/de/tims/fleetstorm/ai/Logic.java index d8b2e9b..ebab5c5 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -173,6 +173,5 @@ public class Logic { public void setClearedLeft(boolean b) { this.clearedLeft = b; - } } diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java index 45b08c4..99c5a8d 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java @@ -32,6 +32,10 @@ public class Matchfield { this.matchfield[x][y].setState(state); } + public void setState(Coordinate coordinate, int state) { + this.matchfield[coordinate.getX()][coordinate.getY()].setState(state); + } + public Coordinate getField(Coordinate coordinate) { return matchfield[coordinate.getX()][coordinate.getY()]; } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index 5579585..1154eb5 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -255,4 +255,5 @@ class LogicTest { assertEquals(logic.getClearedRight(), false); } + } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java index 6db8108..7a6d218 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java @@ -1,6 +1,7 @@ package de.tims.fleetstorm.matchfield; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.stream.Stream; @@ -127,4 +128,17 @@ class MatchfieldCreationTest { matchfield.getField(5, 4)), Arguments.of("below from (5/0) - should be null", matchfield, new Coordinate(5, 0), null)); } + + @Test + void testsetStateOverloaded() { + + Matchfield matchfield = new Matchfield(10); + matchfield.createMatchfield(); + int x = 3; + int y = 3; + matchfield.setState(new Coordinate(x, y), Coordinate.SHIP); + int result = matchfield.getState(x, y); + assertEquals(result, Coordinate.SHIP); + + } }