Browse Source

Added third test case for setShip() (4x1, direction 1)

fleetstorm
Lorenz Hohmann 3 years ago
parent
commit
4426627a5b
  1. 3
      src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java
  2. 6
      src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java

3
src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java

@ -80,7 +80,10 @@ public class Matchfield {
for (int i = 0; i < length; i++) {
this.getField(coordinate).setState(Coordinate.SHIP);
if (direction == 0)
coordinate = this.getRight(coordinate);
if (direction == 1)
coordinate = this.getAbove(coordinate);
}
}

6
src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java

@ -33,11 +33,15 @@ class MatchfieldPositioningTest {
Coordinate[] coordinatesWithShip00_2_0 = new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0) };
Coordinate[] coordinatesWithShip01_3_0 = new Coordinate[] { new Coordinate(0, 1), new Coordinate(1, 1),
new Coordinate(2, 1) };
Coordinate[] coordinatesWithShip02_4_1 = new Coordinate[] { new Coordinate(0, 2), new Coordinate(0, 3),
new Coordinate(0, 4), new Coordinate(0, 5) };
return Stream.of(
Arguments.of("set ship from 0:0, length 2, direction 0", 10, new Coordinate(0, 0), 0, 2,
coordinatesWithShip00_2_0),
Arguments.of("set ship from 0:1, length 3, direction 0", 10, new Coordinate(0, 1), 0, 3,
coordinatesWithShip01_3_0));
coordinatesWithShip01_3_0),
Arguments.of("set ship from 0:2, length 4, direction 1", 10, new Coordinate(0, 2), 1, 4,
coordinatesWithShip02_4_1));
}
}
Loading…
Cancel
Save