From d703a7b1c6fa91280b1cd2c1e678fded3a00d098 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)); } }