Browse Source

Added second test case for setShip() (3x1, direction 0)

fleetstorm
Lorenz Hohmann 3 years ago
parent
commit
d47d765c92
  1. 7
      src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java
  2. 11
      src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java

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

@ -77,8 +77,11 @@ public class Matchfield {
* direction 0 => x axis (to the right) direction 1 => y axis (to the bottom)
*/
public void setShip(Coordinate coordinate, int length, int direction) {
this.setState(coordinate, Coordinate.SHIP);
this.setState(this.getRight(coordinate), Coordinate.SHIP);
for (int i = 0; i < length; i++) {
this.getField(coordinate).setState(Coordinate.SHIP);
coordinate = this.getRight(coordinate);
}
}
}

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

@ -31,8 +31,13 @@ class MatchfieldPositioningTest {
static Stream<Arguments> testShipPositioning() {
Coordinate[] coordinatesWithShip00_2_0 = new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0) };
return Stream.of(Arguments.of("set ship from 0:0, length 2, direction 0", 10, new Coordinate(0, 0), 0, 2,
coordinatesWithShip00_2_0));
Coordinate[] coordinatesWithShip01_3_0 = new Coordinate[] { new Coordinate(0, 1), new Coordinate(1, 1),
new Coordinate(2, 1) };
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));
}
}
Loading…
Cancel
Save