|
|
@ -1,6 +1,7 @@ |
|
|
|
|
|
|
|
package de.tims.fleetstorm.matchfield; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.junit.Assert.assertFalse; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
|
|
|
@ -28,7 +29,7 @@ class MatchfieldShipTest { |
|
|
|
shipSetCounter++; |
|
|
|
} |
|
|
|
|
|
|
|
assertTrue(shipSetCounter == length); |
|
|
|
assertThat(shipSetCounter).describedAs(testName).isEqualTo(length); |
|
|
|
} |
|
|
|
|
|
|
|
static Stream<Arguments> testShipPositioning() { |
|
|
@ -57,10 +58,10 @@ class MatchfieldShipTest { |
|
|
|
boolean calculatedResult = matchfield.setShip(coordinate, length, direction); |
|
|
|
|
|
|
|
if (expectedResult) |
|
|
|
assertTrue(calculatedResult); |
|
|
|
assertThat(calculatedResult).describedAs(testName).isEqualTo(true); |
|
|
|
|
|
|
|
if (!expectedResult) |
|
|
|
assertFalse(calculatedResult); |
|
|
|
assertThat(calculatedResult).describedAs(testName).isEqualTo(false); |
|
|
|
} |
|
|
|
|
|
|
|
static Stream<Arguments> testShipPositioningFailed() { |
|
|
@ -77,28 +78,38 @@ class MatchfieldShipTest { |
|
|
|
matchfield.createMatchfield(); |
|
|
|
|
|
|
|
matchfield.setShip(new Coordinate(0, 0), 5, 1); |
|
|
|
assertFalse(matchfield.setShip(new Coordinate(0, 1), 5, 1)); |
|
|
|
assertThat(matchfield.setShip(new Coordinate(0, 1), 5, 1)).describedAs("set ship on coordinate with ship") |
|
|
|
.isEqualTo(false); |
|
|
|
|
|
|
|
assertTrue(matchfield.setShip(new Coordinate(1, 1), 4, 0)); |
|
|
|
assertFalse(matchfield.setShip(new Coordinate(4, 1), 2, 1)); |
|
|
|
assertThat(matchfield.setShip(new Coordinate(1, 1), 4, 0)).describedAs("set ship on coordinate without ship") |
|
|
|
.isEqualTo(true); |
|
|
|
assertThat(matchfield.setShip(new Coordinate(4, 1), 2, 1)) |
|
|
|
.describedAs("set second ship on coordinate without ship").isEqualTo(false); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testIfAllShipsOnMatchfieldHit() { |
|
|
|
void testIfAllShipsHitReturnsFalseWhenNoShipIsHit() { |
|
|
|
Matchfield matchfield = new Matchfield(10); |
|
|
|
matchfield.createMatchfield(); |
|
|
|
|
|
|
|
matchfield.setShip(new Coordinate(0, 0), 5, 1); |
|
|
|
|
|
|
|
boolean calulatedResult = matchfield.areAllShipsHit(); |
|
|
|
assertFalse(calulatedResult); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testIfAllShipsHitReturnsTrueWhenAllShipsAreHit() { |
|
|
|
Matchfield matchfield = new Matchfield(10); |
|
|
|
matchfield.createMatchfield(); |
|
|
|
|
|
|
|
matchfield.setShip(new Coordinate(0, 0), 5, 1); |
|
|
|
matchfield.getField(0, 0).setState(Coordinate.HIT); |
|
|
|
matchfield.getField(0, 1).setState(Coordinate.HIT); |
|
|
|
matchfield.getField(0, 2).setState(Coordinate.HIT); |
|
|
|
matchfield.getField(0, 3).setState(Coordinate.HIT); |
|
|
|
matchfield.getField(0, 4).setState(Coordinate.HIT); |
|
|
|
calulatedResult = matchfield.areAllShipsHit(); |
|
|
|
|
|
|
|
boolean calulatedResult = matchfield.areAllShipsHit(); |
|
|
|
assertTrue(calulatedResult); |
|
|
|
} |
|
|
|
} |