Browse Source

Added shoot() function to Coordinate class with first test case

Lorenz Hohmann 3 years ago
parent
commit
5cae5a9f2b
  1. 4
      src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java
  2. 19
      src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java

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

@ -44,4 +44,8 @@ public class Coordinate {
System.out.println("X = " + this.x + ", Y = " + this.y + ", State = " + this.state);
}
public void shoot() {
this.setState(Coordinate.HIT);
}
}

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

@ -44,4 +44,23 @@ class CoordinateTest {
Arguments.of("State = EMPTY", 0, Coordinate.EMPTY, Coordinate.EMPTY));
}
@ParameterizedTest(name = "test if shoot function sets correct field states")
@MethodSource("ShootFunctionFieldStates")
void testShootFunctionSetsCorrectFieldStates(String testName, Coordinate coordinateToTest, int expectedState) {
Matchfield matchfield = new Matchfield(10);
matchfield.createMatchfield();
// set dummy ship
matchfield.setShip(new Coordinate(0, 0), 5, 0);
Coordinate realCoordinate = matchfield.getField(coordinateToTest);
realCoordinate.shoot();
int calculatedResult = realCoordinate.getState();
assertThat(calculatedResult).describedAs(testName).isEqualTo(expectedState);
}
static Stream<Arguments> ShootFunctionFieldStates() {
return Stream.of(Arguments.of("Field State is HIT", new Coordinate(0, 0), Coordinate.HIT));
}
}
Loading…
Cancel
Save