@Test(expected = GameException.class) public void testIllegalPlacementThrowsException() { Ship ship = Ship.createHorizontal(new Position(9, 9), 1); Ship otherShip = Ship.createHorizontal(new Position(9, 9), 1); board.placeShip(ship); board.placeShip(otherShip); }
@Test public void testAllShipsSunkIsFalseIfSomeShipsPartiallyRemain() { Ship ship = Ship.createHorizontal(new Position(0, 0), 2); Ship otherShip = Ship.createVertical(new Position(3, 3), 3); board.placeShip(ship); board.placeShip(otherShip); board.shootAt(new Position(0, 0)); board.shootAt(new Position(1, 0)); board.shootAt(new Position(3, 3)); assertThat(board.allShipsSunk(), is(false)); }
@Test public void testIsNotPlaceableIfOtherShipBordersInYDirection() { board.placeShip(Ship.createHorizontal(new Position(0, 1), 5)); Ship ship = Ship.createHorizontal(new Position(0, 0), 1); assertThat(board.shipIsPlaceable(ship), is(false)); }
@Test public void testShipIsNotPlaceableIfOtherShipIsOnSpot() { board.placeShip(Ship.createHorizontal(new Position(0, 0), 5)); Ship ship = Ship.createHorizontal(new Position(4, 0), 2); assertThat(board.shipIsPlaceable(ship), is(false)); }
@Test public void testAllShipsSunkIsTrueIfAllShipsWereFullyHit() { Ship ship = Ship.createHorizontal(new Position(0, 0), 2); board.placeShip(ship); board.shootAt(new Position(0, 0)); board.shootAt(new Position(1, 0)); assertThat(board.allShipsSunk(), is(true)); }