public void GivenMapWithShipPlaced_WhenPlacingShipOverlappingOtherShip_DoesNotAddShipToCells() { const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player); map.Place(ship, coordinate, Direction.East); var overLappingShip = ShipStub.FullStub(this.player); try { map.Place(overLappingShip, coordinate, Direction.East); } catch (Exception) { //No-Op } var cellsWithOccupants = map.Cells.Where(x => x.Occupied); foreach (var cellsWithOccupant in cellsWithOccupants) { Assert.That(!overLappingShip.Cells.Contains(cellsWithOccupant)); } }
public void GivenMapWithShipPlaced_WhenPlacingShipOverlappingOtherShip_ThrowsException() { const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player); map.Place(ship, coordinate, Direction.West); var overLappingShip = ShipStub.FullStub(this.player); Assert.Throws <InvalidOperationException>(() => map.Place(overLappingShip, coordinate, Direction.East)); }
public void GivenMap_WhenPlacingShipWithInvalidDirection_ThrowsException(Direction direction) { const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player); Assert.Throws <InvalidOperationException>(() => map.Place(ship, coordinate, direction)); }
public void GivenMap_WhenPlacingShipWithDirectionLeadingToOutOfBounds_ThrowsException(Direction direction) { const int width = 1; const int height = 1; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player, new WeaponStub(player, 1, WeaponType.SingleShot)); Assert.Throws <InvalidOperationException>(() => map.Place(ship, coordinate, direction)); }
public void GivenMap_WhenPlacingShipOfOtherPlayer_ThrowsException() { const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var otherPlayer = new BattleshipPlayer("OtherPlayer", 'A', PlayerType.One); var ship = ShipStub.FullStub(otherPlayer); Assert.Throws <InvalidOperationException>(() => map.Place(ship, coordinate, Direction.East)); }
public void GivenMap_WhenPlacingShip_PlacesShip(Direction direction) { const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player); map.Place(ship, coordinate, direction); var cellOccupants = map.Cells.Where(x => x.Occupied).Select(x => x.OccupiedBy).ToList(); foreach (var segment in ship.Cells) { Assert.Contains(segment, map.Cells.ToList()); } }
public void GivenMap_WhenPlacingShipWithDirectionLeadingToOutOfBounds_DoesAddShipToCells(Direction direction) { const int width = 1; const int height = 1; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player); try { map.Place(ship, coordinate, direction); } catch (Exception) { //No-Op } var cellsWithOccupants = map.Cells.Where(x => x.Occupied); Assert.IsEmpty(cellsWithOccupants); }