Browse Source

Implemented areAllShipsHit() with first test case if no ship was hit

fleetstorm
Lorenz Hohmann 3 years ago
parent
commit
abeaff8d7b
  1. 5
      src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java
  2. 13
      src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java

5
src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java

@ -41,7 +41,6 @@ public class Matchfield {
} }
public Coordinate getField(int x, int y) { public Coordinate getField(int x, int y) {
return this.matchfield[x][y]; return this.matchfield[x][y];
} }
@ -97,4 +96,8 @@ public class Matchfield {
return true; return true;
} }
public boolean areAllShipsHit() {
return false;
}
} }

13
src/test/java/de/tims/fleetstorm/matchfield/MatchfieldPositioningTest.java → src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java

@ -11,7 +11,7 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.MethodSource;
class MatchfieldPositioningTest {
class MatchfieldShipTest {
@ParameterizedTest(name = "ship was set on the correct positions") @ParameterizedTest(name = "ship was set on the correct positions")
@MethodSource("testShipPositioning") @MethodSource("testShipPositioning")
@ -82,4 +82,15 @@ class MatchfieldPositioningTest {
assertTrue(matchfield.setShip(new Coordinate(1, 1), 4, 0)); assertTrue(matchfield.setShip(new Coordinate(1, 1), 4, 0));
assertFalse(matchfield.setShip(new Coordinate(4, 1), 2, 1)); assertFalse(matchfield.setShip(new Coordinate(4, 1), 2, 1));
} }
@Test
void testIfAllShipsOnMatchfieldHit() {
Matchfield matchfield = new Matchfield(10);
matchfield.createMatchfield();
matchfield.setShip(new Coordinate(0, 0), 5, 1);
boolean calulatedResult = matchfield.areAllShipsHit();
assertFalse(calulatedResult);
}
} }
Loading…
Cancel
Save