Browse Source

add getAbove() in Matchfield - DefaultCase

fleetstorm
Max Wenzel 3 years ago
committed by Lorenz Hohmann
parent
commit
958fcf7166
  1. 12
      src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java
  2. 1
      src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java
  3. 13
      src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java

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

@ -32,4 +32,16 @@ public class Matchfield {
this.matchfield[x][y].setState(state);
}
public Coordinate getAbove(Coordinate center) {
return this.matchfield[center.getX() + 1][center.getY()];
}
public Coordinate getField(Coordinate coordinate) {
return matchfield[coordinate.getX()][coordinate.getY()];
}
public Coordinate getField(int x, int y) {
return matchfield[x][y];
}
}

1
src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java

@ -43,4 +43,5 @@ class CoordinateTest {
Arguments.of("State = HIT", 3, Coordinate.HIT, Coordinate.HIT),
Arguments.of("State = EMPTY", 0, Coordinate.EMPTY, Coordinate.EMPTY));
}
}

13
src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java

@ -63,4 +63,17 @@ class MatchfieldCreationTest {
return Stream.of(
Arguments.of("field x:0 y:0 has state SHIP after setState()", 0, 0, Coordinate.SHIP, Coordinate.SHIP));
}
@ParameterizedTest(name = "Get the Coordinate above")
@MethodSource("getCoordinateAbove")
void testGetAbove(String testName, Matchfield matchfield, Coordinate center, Coordinate expectedResult) {
Coordinate result = matchfield.getAbove(center);
assertThat(result).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> getCoordinateAbove() {
Matchfield matchfield = new Matchfield(10);
return Stream.of(Arguments.of("above from (5/5)", matchfield, new Coordinate(5, 5), matchfield.getField(6, 5)));
}
}
Loading…
Cancel
Save