public void place_battleship_return_false() { //Arrange ICreateBoard createBoard = new CreateNewBoard(); var board = createBoard.CreateBoard(); //Assuming the first cell is occupied foreach (var cells in board.BoardCells) { cells.IsOccupied = true; break; } //Creating a ship with 0 width IBattleship battleShip = new Battleship { Width = 5, Orientation = OrientationType.Horizontal }; IBoardCell firstCell = new BoardCell { RowCoordinate = 1, ColumnCoordinate = 1 }; //Act var result = _placeBattleship.CanShipBePlaced(battleShip, firstCell, board); //Assert Assert.AreEqual(false, result); }
public void place_battleship_return_true() { //Arrange ICreateBoard createBoard = new CreateNewBoard(); var board = createBoard.CreateBoard(); //Creating a ship with 0 width IBattleship battleShip = new Battleship { Width = 3, Orientation = OrientationType.Horizontal }; IBoardCell firstCell = new BoardCell { RowCoordinate = 1, ColumnCoordinate = 1 }; //Act var result = _placeBattleship.CanShipBePlaced(battleShip, firstCell, board); //Assert Assert.AreEqual(true, result); }
public void _hit_is_recorded() { //Arrange ICreateBoard createBoard = new CreateNewBoard(); var board = createBoard.CreateBoard(); //Assuming the first cell is occupied foreach (var cells in board.BoardCells) { cells.IsOccupied = true; break; } IBoardCell cellToAttack = new BoardCell { RowCoordinate = 1, ColumnCoordinate = 1, IsHit = false, IsOccupied = false }; //Act var result = _attack.AttackShip(board, cellToAttack); //Assert Assert.AreEqual(AttackResult.Hit, result); }
public void _board_cell_null_exception_thrown() { //Arrange ICreateBoard createBoard = new CreateNewBoard(); var board = createBoard.CreateBoard(); IBoardCell cellToAttack = null; //Act and Assert Assert.Throws <BoardCellNullException>(() => _attack.AttackShip(board, cellToAttack)); }
public void _miss_is_recorded() { //Arrange ICreateBoard createBoard = new CreateNewBoard(); var board = createBoard.CreateBoard(); IBoardCell cellToAttack = new BoardCell { RowCoordinate = 1, ColumnCoordinate = 1, IsHit = false, IsOccupied = false }; //Act var result = _attack.AttackShip(board, cellToAttack); //Assert Assert.AreEqual(AttackResult.Miss, result); }
public void _ship_width_less_than_one_exception() { //Arrange ICreateBoard createBoard = new CreateNewBoard(); var board = createBoard.CreateBoard(); //Creating a ship with 0 width IBattleship battleShip = new Battleship { Width = 0, Orientation = OrientationType.Horizontal }; IBoardCell firstCell = new BoardCell { RowCoordinate = 1, ColumnCoordinate = 1 }; //Act and Assert Assert.Throws <ShipWidthCannotBeLessThanOneException>(() => _placeBattleship.CanShipBePlaced(battleShip, firstCell, board)); }