From 958fcf71660d9450e233e37175f669c7f9d5a2f7 Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Wed, 12 Jan 2022 15:21:24 +0100 Subject: [PATCH] add getAbove() in Matchfield - DefaultCase --- .../de/tims/fleetstorm/matchfield/Matchfield.java | 12 ++++++++++++ .../tims/fleetstorm/matchfield/CoordinateTest.java | 1 + .../matchfield/MatchfieldCreationTest.java | 13 +++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java index 7a30858..1716226 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java +++ b/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]; + } + } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java b/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java index 488aeda..3de5fc8 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java +++ b/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)); } + } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java index ce47268..d4c5f3a 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java +++ b/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 getCoordinateAbove() { + Matchfield matchfield = new Matchfield(10); + return Stream.of(Arguments.of("above from (5/5)", matchfield, new Coordinate(5, 5), matchfield.getField(6, 5))); + } }