Browse Source

Added test case when field was already shot (expect false)

Lorenz Hohmann 3 years ago
parent
commit
77656709eb
  1. 3
      src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java
  2. 2
      src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java

3
src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java

@ -45,6 +45,9 @@ public class Coordinate {
}
public boolean shoot() {
if (this.state == Coordinate.SHOT)
return false;
if (this.state == Coordinate.SHIP) {
this.state = Coordinate.HIT;
return true;

2
src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java

@ -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;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -74,6 +75,7 @@ class CoordinateTest {
matchfield.setShip(new Coordinate(3, 3), 4, 1);
assertTrue(matchfield.getField(0, 0).shoot());
assertFalse(matchfield.getField(0, 0).shoot());
}
}
Loading…
Cancel
Save