From b8e0dad737831d24eaadc42161bc23c1dba4359c Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Wed, 12 Jan 2022 16:37:13 +0100 Subject: [PATCH] add getAbove() in Matchfield - Case: nothingAbove --- src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java | 4 +++- .../tims/fleetstorm/matchfield/MatchfieldCreationTest.java | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java index f98cc81..919bbe9 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java @@ -56,7 +56,9 @@ public class Matchfield { } public Coordinate getAbove(Coordinate center) { - + if (center.getY() == matchfield.length - 1) { + return null; + } 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 d62cf69..41f1790 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java @@ -106,7 +106,9 @@ class MatchfieldCreationTest { 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))); + return Stream.of( + Arguments.of("above from (5/5) - should be (5,6)", matchfield, new Coordinate(5, 5), + matchfield.getField(5, 6)), + Arguments.of("above from (5/9) - should be null", matchfield, new Coordinate(5, 5), null)); } }