Browse Source

Added Test case when one coordinate is hit, but others on free field (isFreePosition() method)

fleetstorm
Lorenz Hohmann 3 years ago
parent
commit
a05c6c09b9
  1. 4
      src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java
  2. 4
      src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java

4
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);
}
}

4
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));
}
}
Loading…
Cancel
Save