From d47d765c9272a590ceaed89a6ab942f4e7f5f0d9 Mon Sep 17 00:00:00 2001 From: Lorenz Hohmann Date: Sat, 15 Jan 2022 13:34:18 +0100 Subject: [PATCH] Added second test case for setShip() (3x1, direction 0) --- .../de/tims/fleetstorm/matchfield/Matchfield.java | 7 +++++-- .../matchfield/MatchfieldPositioningTest.java | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java index 1d5bdb1..cf50512 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java @@ -77,8 +77,11 @@ public class Matchfield { * direction 0 => x axis (to the right) direction 1 => y axis (to the bottom) */ public void setShip(Coordinate coordinate, int length, int direction) { - this.setState(coordinate, Coordinate.SHIP); - this.setState(this.getRight(coordinate), Coordinate.SHIP); + + for (int i = 0; i < length; i++) { + this.getField(coordinate).setState(Coordinate.SHIP); + coordinate = this.getRight(coordinate); + } } } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java index 22d6723..9f7c02c 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java @@ -31,8 +31,13 @@ class MatchfieldPositioningTest { static Stream testShipPositioning() { Coordinate[] coordinatesWithShip00_2_0 = new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0) }; - - return Stream.of(Arguments.of("set ship from 0:0, length 2, direction 0", 10, new Coordinate(0, 0), 0, 2, - coordinatesWithShip00_2_0)); + Coordinate[] coordinatesWithShip01_3_0 = new Coordinate[] { new Coordinate(0, 1), new Coordinate(1, 1), + new Coordinate(2, 1) }; + + 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)); } }