From 6ea7194b5a2451807d3041d0caa9b8058c4f5b81 Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Wed, 12 Jan 2022 15:24:59 +0100 Subject: [PATCH] add getAbove() in Matchfield - Case: nothingAbove --- src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java | 3 +++ .../tims/fleetstorm/matchfield/MatchfieldCreationTest.java | 5 ++++- 2 files changed, 7 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 1716226..5dac96f 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java @@ -41,6 +41,9 @@ public class Matchfield { } public Coordinate getField(int x, int y) { + if (x == 0) { + return null; + } return matchfield[x][y]; } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java index d4c5f3a..c829a9d 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java @@ -74,6 +74,9 @@ class MatchfieldCreationTest { 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))); + return Stream.of( + Arguments.of("above from (5/5) - should be (6,5)", matchfield, new Coordinate(5, 5), + matchfield.getField(6, 5)), + Arguments.of("above from (0/5) - should be null", matchfield, new Coordinate(0, 5), null)); } }