From ac41493feb3a58e4d605d48feb922cd8c3c228c4 Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Wed, 12 Jan 2022 15:34:51 +0100 Subject: [PATCH] add getBelow() in Matchfield - DefaultCase --- .../de/tims/fleetstorm/matchfield/Matchfield.java | 7 ++++++- .../matchfield/MatchfieldCreationTest.java | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java index 5dac96f..e803cee 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java @@ -44,7 +44,12 @@ public class Matchfield { if (x == 0) { return null; } - return matchfield[x][y]; + return this.matchfield[x][y]; + } + + public Coordinate getBelow(Coordinate center) { + // TODO Auto-generated method stub + return this.matchfield[center.getX() - 1][center.getY()]; } } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java index c829a9d..edb160c 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java @@ -79,4 +79,18 @@ class MatchfieldCreationTest { matchfield.getField(6, 5)), Arguments.of("above from (0/5) - should be null", matchfield, new Coordinate(0, 5), null)); } + + @ParameterizedTest(name = "Get the Coordinate below") + @MethodSource("getCoordinateBelow") + void testGetBelow(String testName, Matchfield matchfield, Coordinate center, Coordinate expectedResult) { + + Coordinate result = matchfield.getBelow(center); + assertThat(result).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream getCoordinateBelow() { + Matchfield matchfield = new Matchfield(10); + return Stream.of(Arguments.of("bewlow from (5/5) - should be (4,5)", matchfield, new Coordinate(5, 5), + matchfield.getField(4, 5))); + } }