|
@ -1,8 +1,14 @@ |
|
|
package de.tims.fleetstorm.matchfield; |
|
|
package de.tims.fleetstorm.matchfield; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest; |
|
|
|
|
|
import org.junit.jupiter.params.provider.Arguments; |
|
|
|
|
|
import org.junit.jupiter.params.provider.MethodSource; |
|
|
|
|
|
|
|
|
class CoordinateTest { |
|
|
class CoordinateTest { |
|
|
|
|
|
|
|
@ -23,22 +29,18 @@ class CoordinateTest { |
|
|
assertEquals(coordinate.getState(), 0); |
|
|
assertEquals(coordinate.getState(), 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void testGetAndSetForAllStates() { |
|
|
|
|
|
coordinate.setState(Coordinate.SHIP); |
|
|
|
|
|
assertEquals(coordinate.getState(), Coordinate.SHIP); |
|
|
|
|
|
assertEquals(coordinate.getState(), 1); |
|
|
|
|
|
|
|
|
|
|
|
coordinate.setState(Coordinate.SHOT); |
|
|
|
|
|
assertEquals(coordinate.getState(), Coordinate.SHOT); |
|
|
|
|
|
assertEquals(coordinate.getState(), 2); |
|
|
|
|
|
|
|
|
|
|
|
coordinate.setState(Coordinate.HIT); |
|
|
|
|
|
assertEquals(coordinate.getState(), Coordinate.HIT); |
|
|
|
|
|
assertEquals(coordinate.getState(), 3); |
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "All Getters/Setters are working") |
|
|
|
|
|
@MethodSource("AllGettersAreWorking") |
|
|
|
|
|
void testGetAndSetForAllStates(String testName, int state, int stateCode, int expectedResult) { |
|
|
|
|
|
coordinate.setState(state); |
|
|
|
|
|
int result = coordinate.getState(); |
|
|
|
|
|
assertThat(result).describedAs(testName).isEqualTo(expectedResult); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
coordinate.setState(Coordinate.EMPTY); |
|
|
|
|
|
assertEquals(coordinate.getState(), Coordinate.EMPTY); |
|
|
|
|
|
assertEquals(coordinate.getState(), 0); |
|
|
|
|
|
|
|
|
static Stream<Arguments> AllGettersAreWorking() { |
|
|
|
|
|
return Stream.of(Arguments.of("State = SHIP", 1, Coordinate.SHIP, Coordinate.SHIP), |
|
|
|
|
|
Arguments.of("State = SHOT", 2, Coordinate.SHOT, Coordinate.SHOT), |
|
|
|
|
|
Arguments.of("State = HIT", 3, Coordinate.HIT, Coordinate.HIT), |
|
|
|
|
|
Arguments.of("State = EMPTY", 0, Coordinate.EMPTY, Coordinate.EMPTY)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |