From abeaff8d7b9fada908b7c1aff6249d28ea194f58 Mon Sep 17 00:00:00 2001 From: Lorenz Hohmann Date: Mon, 17 Jan 2022 14:59:00 +0100 Subject: [PATCH] Implemented areAllShipsHit() with first test case if no ship was hit --- .../de/tims/fleetstorm/matchfield/Matchfield.java | 5 ++++- ...PositioningTest.java => MatchfieldShipTest.java} | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) rename src/test/java/de/tims/fleetstorm/matchfield/{MatchfieldPositioningTest.java => MatchfieldShipTest.java} (91%) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java index f9fcd5e..a3e4abe 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java @@ -41,7 +41,6 @@ public class Matchfield { } public Coordinate getField(int x, int y) { - return this.matchfield[x][y]; } @@ -97,4 +96,8 @@ public class Matchfield { return true; } + public boolean areAllShipsHit() { + return false; + } + } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java similarity index 91% rename from src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java rename to src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java index 6ad6bb7..5052bf3 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java @@ -11,7 +11,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -class MatchfieldPositioningTest { +class MatchfieldShipTest { @ParameterizedTest(name = "ship was set on the correct positions") @MethodSource("testShipPositioning") @@ -82,4 +82,15 @@ class MatchfieldPositioningTest { assertTrue(matchfield.setShip(new Coordinate(1, 1), 4, 0)); assertFalse(matchfield.setShip(new Coordinate(4, 1), 2, 1)); } + + @Test + void testIfAllShipsOnMatchfieldHit() { + Matchfield matchfield = new Matchfield(10); + matchfield.createMatchfield(); + + matchfield.setShip(new Coordinate(0, 0), 5, 1); + + boolean calulatedResult = matchfield.areAllShipsHit(); + assertFalse(calulatedResult); + } }