Browse Source

add getAbove() in Matchfield - DefaultCase

fleetstorm
Max Wenzel 3 years ago
committed by Lorenz Hohmann
parent
commit
304b3c943e
  1. 17
      src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java
  2. 18
      src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java

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

@ -32,6 +32,15 @@ public class Matchfield {
this.matchfield[x][y].setState(state);
}
public Coordinate getField(Coordinate coordinate) {
return matchfield[coordinate.getX()][coordinate.getY()];
}
public Coordinate getField(int x, int y) {
return this.matchfield[x][y];
}
public Coordinate getRight(Coordinate center) {
if (center.getX() == matchfield.length - 1) {
return null;
@ -46,13 +55,9 @@ public class Matchfield {
return this.matchfield[center.getX() - 1][center.getY()];
}
public Coordinate getField(Coordinate coordinate) {
return matchfield[coordinate.getX()][coordinate.getY()];
}
public Coordinate getAbove(Coordinate center) {
public Coordinate getField(int x, int y) {
return this.matchfield[x][y];
return matchfield[center.getX()][center.getY() + 1];
}
}

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

@ -66,7 +66,7 @@ class MatchfieldCreationTest {
@ParameterizedTest(name = "Get the Coordinate right")
@MethodSource("getCoordinateRight")
void testGetAbove(String testName, Matchfield matchfield, Coordinate center, Coordinate expectedResult) {
void testGetRight(String testName, Matchfield matchfield, Coordinate center, Coordinate expectedResult) {
Coordinate result = matchfield.getRight(center);
assertThat(result).describedAs(testName).isEqualTo(expectedResult);
@ -82,7 +82,7 @@ class MatchfieldCreationTest {
@ParameterizedTest(name = "Get the Coordinate left")
@MethodSource("getCoordinateLeft")
void testGetBelow(String testName, Matchfield matchfield, Coordinate center, Coordinate expectedResult) {
void testGetLeft(String testName, Matchfield matchfield, Coordinate center, Coordinate expectedResult) {
Coordinate result = matchfield.getLeft(center);
assertThat(result).describedAs(testName).isEqualTo(expectedResult);
@ -95,4 +95,18 @@ class MatchfieldCreationTest {
matchfield.getField(4, 5)),
Arguments.of("left from (0/5) - should be null", matchfield, new Coordinate(0, 5), null));
}
@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) - should be (5,6)", matchfield, new Coordinate(5, 5),
matchfield.getField(5, 6)));
}
}
Loading…
Cancel
Save