Browse Source

Added second test case for invalid coordinates on setShip (5x1, direction 1)

fleetstorm
Lorenz Hohmann 2 years ago
parent
commit
65ad351305
  1. 15
      src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java

15
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<Arguments> 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));
}
}
Loading…
Cancel
Save