public void AddBattleShip_Single_Ship(int playerId) { // Arrange var battleShip = BattleShip.CreateBattleship(playerId, 1, 1, 5, true); // Act & Assert var board = Board.CreateBoard(playerId); board.AddBattleShip(battleShip); }
public override void HandleCommand(AddBattleShipCommand command) { var board = _gameManager.GetBoard(command.PlayerId); var battleShip = BattleShip.CreateBattleship( command.PlayerId, command.StartingRow, command.StartingColumn, command.Size, command.IsHorizontal); board.AddBattleShip(battleShip); }
public void TakeAttack_Test(int size, int attackAtRow, int attackAtColumn, int expectedHealth, bool isSunk) { // Arrange var battleShip = BattleShip.CreateBattleship(1, 1, 1, size, true); // Act battleShip.TakeAttack(Coordinate.CreateCoordinate(attackAtRow, attackAtColumn)); // Act battleShip.Health.Should().Be(expectedHealth); battleShip.IsSunk.Should().Be(isSunk); }
public void AddBattleShip_Two_Ships_At_Different_Places(int playerId) { // Arrange var battleShip = BattleShip.CreateBattleship(playerId, 1, 1, 5, true); var battleShip2 = BattleShip.CreateBattleship(playerId, 1, 6, 5, true); // Act & Assert var board = Board.CreateBoard(playerId); board.AddBattleShip(battleShip); board.AddBattleShip(battleShip2); }
public void IsPositionOccupied_Test(int row, int column, bool isOccupied) { // Arrange var battleShip = BattleShip.CreateBattleship(1, 1, 1, 5, true); // Act var board = Board.CreateBoard(1); board.AddBattleShip(battleShip); // Assert board.IsPositionOccupied(Coordinate.CreateCoordinate(row, column)).Should().Be(isOccupied); }
public void AddBattleShip_Two_Ships_Overlapping_Each_Other(int playerId) { // Arrange var battleShip = BattleShip.CreateBattleship(playerId, 1, 1, 5, true); var battleShip2 = BattleShip.CreateBattleship(playerId, 1, 3, 5, false); // Act & Assert var board = Board.CreateBoard(playerId); board.AddBattleShip(battleShip); Assert.Throws <BoardPositionAlreadyOccupiedException>(() => board.AddBattleShip(battleShip2), "Cannot add battle ship the area that it will occupy already overlaps with another ship"); }
public void AttackPosition_At_Occupied_Positions(int attackAtRow, int attackAtColumn, string attackResult) { // Arrange var board = Board.CreateBoard(1); var battleShip = BattleShip.CreateBattleship(1, 1, 1, 5, true); board.AddBattleShip(battleShip); // Act var result = board.AttackPosition(Coordinate.CreateCoordinate(attackAtRow, attackAtColumn)); // Assert result.Should().Be(attackResult); }
public void TakeAttack_MultipleTimes_Without_Ship_Sinking() { // Arrange var battleShip = BattleShip.CreateBattleship(1, 1, 1, 3, true); // Act battleShip.TakeAttack(Coordinate.CreateCoordinate(1, 1)); // Hit battleShip.TakeAttack(Coordinate.CreateCoordinate(1, 2)); // Hit battleShip.TakeAttack(Coordinate.CreateCoordinate(2, 1)); // Miss battleShip.TakeAttack(Coordinate.CreateCoordinate(5, 5)); // Miss // Act battleShip.Health.Should().Be(1); battleShip.IsSunk.Should().BeFalse(); }
public void CreateBattleship_Test(int row, int column, int size, bool isHorizontal) { // Act var battleShip = BattleShip.CreateBattleship(1, row, column, size, isHorizontal); // Assert battleShip.Should().NotBeNull(); battleShip.PlayerId.Should().Be(1); battleShip.StartingRow.Should().Be(row); battleShip.StartingColumn.Should().Be(column); battleShip.Size.Should().Be(size); battleShip.IsHorizontal.Should().Be(isHorizontal); battleShip.Health.Should().Be(battleShip.Size); battleShip.IsSunk.Should().BeFalse(); battleShip.Coordinates.Count().Should().Be(battleShip.Size); }
public void AttackPosition_To_Sink_Battleship() { // Arrange var board = Board.CreateBoard(1); var battleShip = BattleShip.CreateBattleship(1, 1, 1, 3, true); board.AddBattleShip(battleShip); // Act var result = board.AttackPosition(Coordinate.CreateCoordinate(1, 1)); result.Should().Be("hit"); result = board.AttackPosition(Coordinate.CreateCoordinate(1, 2)); result.Should().Be("hit"); result = board.AttackPosition(Coordinate.CreateCoordinate(3, 1)); result.Should().Be("miss"); result = board.AttackPosition(Coordinate.CreateCoordinate(1, 3)); result.Should().Be("sunk"); }
public void CreateBattleship_Test_With_Invalid_StartingPositions_With_Vertical_Alignment(int row, int size) { // Act & Assert Assert.Throws <InvalidBattleShipException>(() => BattleShip.CreateBattleship(1, row, 1, size, false), "Battleship cannot be placed at this position. Due to the ship's position and size, it will exceed the board's boundaries"); }
public void CreateBattleship_Test_With_Invalid_StartingColumn(int column) { // Act & Assert Assert.Throws <InvalidBattleShipException>(() => BattleShip.CreateBattleship(1, 1, column, 1, true), "Battleship's starting column position should be >= 1 and <= 10"); }
public void CreateBattleship_Test_With_Invalid_StartingRow(int row) { // Act & Assert Assert.Throws <InvalidBattleShipException>(() => BattleShip.CreateBattleship(1, row, 1, 1, true), "Battleship's starting row position should be >= 1 and <= 10"); }
public void CreateBattleship_Test_With_Invalid_Size(int size) { // Act & Assert Assert.Throws <InvalidBattleShipException>(() => BattleShip.CreateBattleship(1, 1, 1, size, true), "Battleship's size should be >= 1 and <= 10"); }