コード例 #1
0
  @Test
  public void testPlaceShip() throws ShipTooCloseException {
    Coordinate[] shipCoordinates = new Coordinate[] {new Coordinate(1, 1)};
    battlefield.placeShip(shipCoordinates);

    assertArrayEquals(new Boolean[] {true}, battlefield.getShipsByCoordinates(shipCoordinates));
  }
コード例 #2
0
  @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));
  }
コード例 #3
0
 @Test
 public void testInitiallyNoShots() {
   assertArrayEquals(
       new Battlefield.ShotResult[] {
         Battlefield.ShotResult.NONE,
         Battlefield.ShotResult.NONE,
         Battlefield.ShotResult.NONE,
         Battlefield.ShotResult.NONE
       },
       battlefield.getShotsByCoordinates(coordinates));
 }
コード例 #4
0
  @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());
  }
コード例 #5
0
 @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)});
 }
コード例 #6
0
 @Test
 public void testInitiallyNoShips() {
   assertArrayEquals(
       new Boolean[] {false, false, false, false}, battlefield.getShipsByCoordinates(coordinates));
 }