|
|
@ -1,17 +1,12 @@ |
|
|
|
package de.tims.fleetstorm.ai; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotEquals; |
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
import de.tims.fleetstorm.matchfield.Coordinate; |
|
|
|
import de.tims.fleetstorm.matchfield.Matchfield; |
|
|
@ -90,7 +85,6 @@ class LogicTest { |
|
|
|
Coordinate result = logic.getLastShot(); |
|
|
|
|
|
|
|
assertEquals(result, expectedResult); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
@ -261,25 +255,23 @@ class LogicTest { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@ParameterizedTest(name = "choose the right Coordinate after Hit") |
|
|
|
@MethodSource("getCorrectNext") |
|
|
|
void testNextChooseFieldAfterHit(String testName, Coordinate center, Coordinate expectedResult) { |
|
|
|
@Test |
|
|
|
void testChooseFieldAboveAfterHit() { |
|
|
|
Logic logic = new Logic(); |
|
|
|
int size = 4; |
|
|
|
Coordinate center = new Coordinate(2, 2); |
|
|
|
Coordinate expectedResult = new Coordinate(2, 3); |
|
|
|
Matchfield matchfield = new Matchfield(size); |
|
|
|
matchfield.createMatchfield(); |
|
|
|
matchfield.setState(center, Coordinate.HIT); |
|
|
|
matchfield.setState(expectedResult, Coordinate.HIT); |
|
|
|
logic.setMatchfield(matchfield); |
|
|
|
logic.setLastShot(center); |
|
|
|
logic.setTarget(center); |
|
|
|
logic.setFoundShip(true); |
|
|
|
|
|
|
|
Coordinate result = logic.chooseField(logic.getEverySecondField()); |
|
|
|
assertThat(result).describedAs(testName).isEqualTo(expectedResult); |
|
|
|
assertEquals(result, expectedResult); |
|
|
|
} |
|
|
|
|
|
|
|
static Stream<Arguments> getCorrectNext() { |
|
|
|
return Stream |
|
|
|
.of(Arguments.of("center (2/2) - target should be (2,3)", new Coordinate(2, 2), new Coordinate(2, 3))); |
|
|
|
} |
|
|
|
} |