From 8e92a1caee506910809d395516da3697fb6b6ef4 Mon Sep 17 00:00:00 2001 From: Lorenz Hohmann Date: Mon, 17 Jan 2022 15:14:18 +0100 Subject: [PATCH] Added third test for areAllShipsHit() when a ship is not fully hit --- .../matchfield/MatchfieldShipTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java index 9948134..cdeb007 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java @@ -112,4 +112,23 @@ class MatchfieldShipTest { boolean calulatedResult = matchfield.areAllShipsHit(); assertTrue(calulatedResult); } + + @Test + void testIfAllShipsHitReturnsFalseWhenTwoShipsAreNotFullyHit() { + Matchfield matchfield = new Matchfield(10); + matchfield.createMatchfield(); + + matchfield.setShip(new Coordinate(0, 0), 5, 1); + matchfield.getField(0, 0).setState(Coordinate.HIT); + matchfield.getField(0, 1).setState(Coordinate.HIT); + matchfield.getField(0, 2).setState(Coordinate.HIT); + matchfield.getField(0, 3).setState(Coordinate.HIT); + matchfield.getField(0, 4).setState(Coordinate.HIT); + + matchfield.setShip(new Coordinate(3, 4), 2, 0); + matchfield.getField(4, 4).setState(Coordinate.HIT); + + boolean calulatedResult = matchfield.areAllShipsHit(); + assertFalse(calulatedResult); + } }