From 4426627a5b19c00576e59c118434b817ab1e4b94 Mon Sep 17 00:00:00 2001 From: Lorenz Hohmann Date: Sat, 15 Jan 2022 13:35:12 +0100 Subject: [PATCH] Added third test case for setShip() (4x1, direction 1) --- src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java | 5 ++++- .../fleetstorm/matchfield/MatchfieldPositioningTest.java | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java index cf50512..726666d 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java @@ -80,7 +80,10 @@ public class Matchfield { for (int i = 0; i < length; i++) { this.getField(coordinate).setState(Coordinate.SHIP); - coordinate = this.getRight(coordinate); + if (direction == 0) + coordinate = this.getRight(coordinate); + if (direction == 1) + coordinate = this.getAbove(coordinate); } } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java index 9f7c02c..72b4359 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java @@ -33,11 +33,15 @@ class MatchfieldPositioningTest { Coordinate[] coordinatesWithShip00_2_0 = new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0) }; Coordinate[] coordinatesWithShip01_3_0 = new Coordinate[] { new Coordinate(0, 1), new Coordinate(1, 1), new Coordinate(2, 1) }; + Coordinate[] coordinatesWithShip02_4_1 = new Coordinate[] { new Coordinate(0, 2), new Coordinate(0, 3), + new Coordinate(0, 4), new Coordinate(0, 5) }; return Stream.of( Arguments.of("set ship from 0:0, length 2, direction 0", 10, new Coordinate(0, 0), 0, 2, coordinatesWithShip00_2_0), Arguments.of("set ship from 0:1, length 3, direction 0", 10, new Coordinate(0, 1), 0, 3, - coordinatesWithShip01_3_0)); + coordinatesWithShip01_3_0), + Arguments.of("set ship from 0:2, length 4, direction 1", 10, new Coordinate(0, 2), 1, 4, + coordinatesWithShip02_4_1)); } }