@Test public void testPlaceShip() throws ShipTooCloseException { Coordinate[] shipCoordinates = new Coordinate[] {new Coordinate(1, 1)}; battlefield.placeShip(shipCoordinates); assertArrayEquals(new Boolean[] {true}, battlefield.getShipsByCoordinates(shipCoordinates)); }
@Test public void testShotAsKill() { Coordinate[] shotCoordinates = new Coordinate[] {new Coordinate(1, 1), new Coordinate(1, 2)}; battlefield.shotAs(Battlefield.ShotResult.KILL, shotCoordinates); assertArrayEquals( new Battlefield.ShotResult[] {Battlefield.ShotResult.KILL, Battlefield.ShotResult.KILL}, battlefield.getShotsByCoordinates(shotCoordinates)); }
@Test public void testInitiallyNoShots() { assertArrayEquals( new Battlefield.ShotResult[] { Battlefield.ShotResult.NONE, Battlefield.ShotResult.NONE, Battlefield.ShotResult.NONE, Battlefield.ShotResult.NONE }, battlefield.getShotsByCoordinates(coordinates)); }
@Test public void testInitialCoordinates() { Coordinate[] initialCoordinates = new Coordinate[Battlefield.SIZE]; int i = 0; for (int x = Battlefield.LOWER_BOUND; x <= Battlefield.UPPER_BOUND; x++) { for (int y = Battlefield.LOWER_BOUND; y <= Battlefield.UPPER_BOUND; y++) { initialCoordinates[i] = new Coordinate(x, y); i++; } } assertArrayEquals(initialCoordinates, battlefield.getCoordinates()); }
@Test(expected = ShipTooCloseException.class) public void testExceptionWhenShipsTooClose() throws ShipTooCloseException { battlefield.placeShip(new Coordinate[] {new Coordinate(1, 1), new Coordinate(1, 2)}); battlefield.placeShip(new Coordinate[] {new Coordinate(2, 1)}); }
@Test public void testInitiallyNoShips() { assertArrayEquals( new Boolean[] {false, false, false, false}, battlefield.getShipsByCoordinates(coordinates)); }