Browse Source

Added second test case for areAllShipsHit() - all ships hit test

fleetstorm
Lorenz Hohmann 3 years ago
parent
commit
27e7a96ba7
  1. 12
      src/main/java/de/tims/fleetstorm/matchfield/Matchfield.java
  2. 8
      src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java

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

@ -97,7 +97,17 @@ public class Matchfield {
}
public boolean areAllShipsHit() {
return false;
int shipCounter = 0;
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
int fieldState = this.matchfield[i][j].getState();
if (fieldState == Coordinate.SHIP)
shipCounter++;
}
}
return shipCounter == 0;
}
}

8
src/test/java/de/tims/fleetstorm/matchfield/MatchfieldShipTest.java

@ -92,5 +92,13 @@ class MatchfieldShipTest {
boolean calulatedResult = matchfield.areAllShipsHit();
assertFalse(calulatedResult);
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();
assertTrue(calulatedResult);
}
}
Loading…
Cancel
Save