From dd87d19b182a089c1440f2f4f078018047b58a32 Mon Sep 17 00:00:00 2001 From: Lorenz Hohmann Date: Sat, 15 Jan 2022 14:40:38 +0100 Subject: [PATCH] Added second test case to shoot(): Call on Coordinate without ship --- .../java/de/tims/fleetstorm/matchfield/Coordinate.java | 7 ++++++- .../java/de/tims/fleetstorm/matchfield/CoordinateTest.java | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java b/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java index f31b14c..7ce2692 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java @@ -45,7 +45,12 @@ public class Coordinate { } public void shoot() { - this.setState(Coordinate.HIT); + if (this.state == Coordinate.SHIP) { + this.state = Coordinate.HIT; + return; + } + + this.state = Coordinate.SHOT; } } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java b/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java index 9705b32..0aefe99 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java @@ -60,7 +60,8 @@ class CoordinateTest { } static Stream ShootFunctionFieldStates() { - return Stream.of(Arguments.of("Field State is HIT", new Coordinate(0, 0), Coordinate.HIT)); + return Stream.of(Arguments.of("Field State is HIT", new Coordinate(0, 0), Coordinate.HIT), + Arguments.of("Field State is SHOT", new Coordinate(0, 1), Coordinate.SHOT)); } }