|
@ -279,12 +279,10 @@ class LogicTest { |
|
|
Logic logic = new Logic(); |
|
|
Logic logic = new Logic(); |
|
|
int size = 4; |
|
|
int size = 4; |
|
|
Coordinate center = new Coordinate(2, 2); |
|
|
Coordinate center = new Coordinate(2, 2); |
|
|
// Coordinate empty = new Coordinate(2, 3); |
|
|
|
|
|
Coordinate expectedResult = new Coordinate(2, 1); |
|
|
Coordinate expectedResult = new Coordinate(2, 1); |
|
|
Matchfield matchfield = new Matchfield(size); |
|
|
Matchfield matchfield = new Matchfield(size); |
|
|
matchfield.createMatchfield(); |
|
|
matchfield.createMatchfield(); |
|
|
matchfield.setState(center, Coordinate.HIT); |
|
|
matchfield.setState(center, Coordinate.HIT); |
|
|
// matchfield.setState(empty, Coordinate.EMPTY); |
|
|
|
|
|
matchfield.setState(expectedResult, Coordinate.HIT); |
|
|
matchfield.setState(expectedResult, Coordinate.HIT); |
|
|
logic.setMatchfield(matchfield); |
|
|
logic.setMatchfield(matchfield); |
|
|
logic.setLastShot(center); |
|
|
logic.setLastShot(center); |
|
@ -297,4 +295,25 @@ class LogicTest { |
|
|
assertEquals(result, expectedResult); |
|
|
assertEquals(result, expectedResult); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void testChooseFieldRightAfterHit() { |
|
|
|
|
|
Logic logic = new Logic(); |
|
|
|
|
|
int size = 4; |
|
|
|
|
|
Coordinate center = new Coordinate(2, 2); |
|
|
|
|
|
Coordinate expectedResult = new Coordinate(3, 2); |
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
logic.chooseField(logic.getEverySecondField()); // first Shot |
|
|
|
|
|
logic.chooseField(logic.getEverySecondField()); // second Shot |
|
|
|
|
|
Coordinate result = logic.chooseField(logic.getEverySecondField()); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(result, expectedResult); |
|
|
|
|
|
} |
|
|
} |
|
|
} |