|
|
@ -21,7 +21,7 @@ class LogicTest { |
|
|
|
matchfield = new Matchfield(size); |
|
|
|
matchfield.createMatchfield(); |
|
|
|
logic.setMatchfield(matchfield); |
|
|
|
ArrayList<Coordinate> everySecondField = logic.getEverySecondField(); |
|
|
|
// ArrayList<Coordinate> everySecondField = logic.getEverySecondField(); |
|
|
|
|
|
|
|
Coordinate calcResult = logic.chooseField(); |
|
|
|
assertNotNull(calcResult); |
|
|
@ -41,9 +41,9 @@ class LogicTest { |
|
|
|
everySecondField.get(i).setState(Coordinate.SHOT); |
|
|
|
} |
|
|
|
matchfield.setState(2, 2, Coordinate.EMPTY); |
|
|
|
logic.setEverySecondField(everySecondField); |
|
|
|
|
|
|
|
Coordinate choosenField = logic.chooseField(); |
|
|
|
int calcState = matchfield.getState(choosenField.getX(), choosenField.getY()); |
|
|
|
int calcState = logic.chooseField().getState(); |
|
|
|
assertNotEquals(calcState, Coordinate.SHOT); |
|
|
|
} |
|
|
|
|
|
|
@ -288,8 +288,7 @@ class LogicTest { |
|
|
|
logic.setLastShot(center); |
|
|
|
logic.setTarget(center); |
|
|
|
logic.setFoundShip(true); |
|
|
|
|
|
|
|
logic.chooseField(); // first Shot |
|
|
|
logic.chooseField();// first Shot |
|
|
|
Coordinate result = logic.chooseField(); // second Shot |
|
|
|
|
|
|
|
assertEquals(result, expectedResult); |
|
|
@ -334,10 +333,44 @@ class LogicTest { |
|
|
|
|
|
|
|
logic.chooseField(); // first Shot |
|
|
|
logic.chooseField(); // second Shot |
|
|
|
logic.chooseField(); // third Shot |
|
|
|
logic.chooseField(); // third Shot Coordinate |
|
|
|
Coordinate result = logic.chooseField(); |
|
|
|
|
|
|
|
assertEquals(result, expectedResult); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testShipIsOnYAxis() { |
|
|
|
int size = 10; |
|
|
|
Logic logic = new Logic(); |
|
|
|
Matchfield matchfield = new Matchfield(size); |
|
|
|
Coordinate s1 = new Coordinate(5, 4); |
|
|
|
Coordinate s2 = new Coordinate(5, 5); |
|
|
|
Coordinate s3 = new Coordinate(5, 6); |
|
|
|
|
|
|
|
matchfield.createMatchfield(); |
|
|
|
matchfield.setState(s1, Coordinate.SHIP); |
|
|
|
matchfield.setState(s2, Coordinate.HIT); |
|
|
|
matchfield.setState(s3, Coordinate.SHIP); |
|
|
|
|
|
|
|
logic.setMatchfield(matchfield); |
|
|
|
logic.setLastShot(s2); |
|
|
|
logic.setTarget(s2); |
|
|
|
logic.setFoundShip(true); |
|
|
|
|
|
|
|
logic.chooseField(); // First shot (s3) |
|
|
|
logic.getMatchfield().setState(s3, Coordinate.HIT); // |
|
|
|
logic.chooseField(); // Second Shot |
|
|
|
logic.getMatchfield().setState(new Coordinate(5, 7), Coordinate.SHOT); |
|
|
|
|
|
|
|
logic.chooseField(); // Third Shot (s1) |
|
|
|
logic.getMatchfield().setState(s1, Coordinate.HIT); // |
|
|
|
logic.chooseField(); // fourth Shot |
|
|
|
|
|
|
|
assertEquals(logic.getFoundShip(), false); |
|
|
|
assertEquals(logic.getClearedAbove(), false); |
|
|
|
assertEquals(logic.getClearedBelow(), false); |
|
|
|
assertEquals(logic.getClearedLeft(), false); |
|
|
|
assertEquals(logic.getClearedRight(), false); |
|
|
|
|
|
|
|
} |
|
|
|
} |