From 304b3c943e0b3fe909f705b51b227640755c1cac Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Wed, 12 Jan 2022 16:30:32 +0100 Subject: [PATCH] add getAbove() in Matchfield - DefaultCase --- .../tims/fleetstorm/matchfield/Matchfield.java | 17 +++++++++++------ .../matchfield/MatchfieldCreationTest.java | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java index 4c2b5b2..f98cc81 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java +++ b/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]; } } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java index e99406d..d62cf69 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java +++ b/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 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))); + } }