public void HasLostTheGame_AllShipsAreStillIntact_GameIsNotLost() { var board = new BattleshipBoard(3); Assert.AreEqual(1, board.AddBattleShip(0, 0, 0, 2)); Assert.AreEqual(2, board.AddBattleShip(1, 0, 2, 0)); Assert.AreEqual(3, board.AddBattleShip(1, 1, 2, 1)); Assert.AreEqual(false, board.HasLostTheGame()); }
public void HasLostTheGame_AllShipsAreDestroyed_GameIsLost() { var board = new BattleshipBoard(3); Assert.AreEqual(1, board.AddBattleShip(0, 0, 0, 2)); Assert.AreEqual(2, board.AddBattleShip(1, 0, 2, 0)); Assert.AreEqual(3, board.AddBattleShip(1, 1, 2, 1)); Assert.AreEqual(BattleshipBoard.AttackResult.Hit, board.TryAttack(0, 1)); // Ship 1 is down Assert.AreEqual(BattleshipBoard.AttackResult.Hit, board.TryAttack(1, 0)); // Ship 2 is down Assert.AreEqual(BattleshipBoard.AttackResult.Hit, board.TryAttack(2, 1)); // Ship 3 is down Assert.AreEqual(true, board.HasLostTheGame()); // At this point, all battleships should be destroyed }
public void HasLostTheGame_NotAllShipsAreDestroyed_GameIsNotLost() { var board = new BattleshipBoard(3); Assert.AreEqual(1, board.AddBattleShip(0, 0, 0, 2)); Assert.AreEqual(2, board.AddBattleShip(1, 0, 2, 0)); Assert.AreEqual(3, board.AddBattleShip(1, 1, 2, 1)); Assert.AreEqual(BattleshipBoard.AttackResult.Hit, board.TryAttack(0, 1)); // Ship 1 is down Assert.AreEqual(BattleshipBoard.AttackResult.Miss, board.TryAttack(0, 1)); // Attacking same location is a miss Assert.AreEqual(BattleshipBoard.AttackResult.Miss, board.TryAttack(0, 0)); // Attacking any part of Ship 1 again will result in a miss Assert.AreEqual(BattleshipBoard.AttackResult.Miss, board.TryAttack(2, 2)); // Attacking at empty location will produce a miss Assert.AreEqual(BattleshipBoard.AttackResult.Hit, board.TryAttack(1, 0)); // Attack ship 2 Assert.AreEqual(false, board.HasLostTheGame()); // At this point, battleship 3 are still alive }
public void HasLostTheGame_EmptyBoard_GameIsNotLost() { var board = new BattleshipBoard(3); Assert.AreEqual(false, board.HasLostTheGame()); }