From 65ad3513055b54b1dcde2c35e9e84f31fa5bf1a7 Mon Sep 17 00:00:00 2001 From: Lorenz Hohmann Date: Sat, 15 Jan 2022 13:38:51 +0100 Subject: [PATCH] Added second test case for invalid coordinates on setShip (5x1, direction 1) --- .../matchfield/MatchfieldPositioningTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java index e969003..2fb254a 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java @@ -49,17 +49,24 @@ class MatchfieldPositioningTest { @ParameterizedTest(name = "ship positioning on invalid or valid coordinates") @MethodSource("testShipPositioningFailed") void testMatchfieldShipSetWithInvalidOrValidCoordinates(String testName, int matchfieldSize, Coordinate coordinate, - int direction, int length) { + int direction, int length, boolean expectedResult) { Matchfield matchfield = new Matchfield(matchfieldSize); matchfield.createMatchfield(); boolean calculatedResult = matchfield.setShip(coordinate, length, direction); - assertFalse(calculatedResult); + + if (expectedResult) + assertTrue(calculatedResult); + + if (!expectedResult) + assertFalse(calculatedResult); } static Stream testShipPositioningFailed() { - return Stream.of( - Arguments.of("invalid ship position from 9:0, length 2, direction 0", 10, new Coordinate(9, 0), 0, 2)); + Arguments.of("invalid ship position from 9:0, length 2, direction 0", 10, new Coordinate(9, 0), 0, 2, + false), + Arguments.of("valid ship position from 8:0, length 5, direction 1", 10, new Coordinate(9, 0), 1, 5, + true)); } }