From a05c6c09b9024c80035afdea548bf0c3ce311f6a Mon Sep 17 00:00:00 2001 From: Lorenz Hohmann Date: Wed, 2 Feb 2022 16:34:42 +0100 Subject: [PATCH] Added Test case when one coordinate is hit, but others on free field (isFreePosition() method) --- src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java | 4 ++-- .../de/tims/fleetstorm/matchfield/MatchfieldShipTest.java | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java index 9190895..ade8efb 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java @@ -118,9 +118,9 @@ public class Matchfield { return false; if (direction == 0) { - next = new Coordinate(next.getX() + i, next.getY()); + next = new Coordinate(next.getX() + 1, next.getY()); } else if (direction == 1) { - next = new Coordinate(next.getX(), next.getY() + i); + next = new Coordinate(next.getX(), next.getY() + 1); } } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java index 72a94c8..b3f1205 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java @@ -148,6 +148,8 @@ class MatchfieldShipTest { Arguments.of("one ship is within the coordinates", new Coordinate(0, 0), 1, 2, new Coordinate[] { new Coordinate(0, 0) }, false), Arguments.of("no ship is within the coordinates", new Coordinate(1, 1), 0, 5, new Coordinate[] {}, - true)); + true), + Arguments.of("one of the coordinates is hit, others on free fields", new Coordinate(5, 5), 1, 3, + new Coordinate[] { new Coordinate(5, 7), new Coordinate(5, 8), new Coordinate(5, 9) }, false)); } }