public void GetStartingSquaresTest() { Grid grid = new Grid(); int length = 3; Grid.Orientation orientation = Grid.Orientation.Horizontal; Square[] actual = grid.GetFreeStartingSquares(length, orientation); Assert.AreEqual(80, actual.Length); Square startingSquare = GetSquare(actual, 3, 3); grid.MakeShip(startingSquare, length, orientation); actual = grid.GetFreeStartingSquares(length, orientation); Assert.AreEqual(59, actual.Length); Assert.IsNull(GetSquare(actual, 3, 3)); Assert.IsNull(GetSquare(actual, 3, 4)); Assert.IsNull(GetSquare(actual, 3, 5)); Assert.IsNull(GetSquare(actual, 2, 2)); Assert.IsNull(GetSquare(actual, 4, 6)); }
public void FireTest() { Grid grid = new Grid(); int length = 3; Grid.Orientation orientation = Grid.Orientation.Horizontal; Square[] squares = grid.GetFreeStartingSquares(length, orientation); Square startingSquare = squares[10]; Ship ship = grid.MakeShip(startingSquare, length, orientation); int row = startingSquare.Row; int column = startingSquare.Column; Assert.AreEqual(HitResults.Hit, ship.Fire(row, column)); Assert.AreEqual(HitResults.Hit, ship.Fire(row, column + 1)); Assert.AreEqual(HitResults.Sunk, ship.Fire(row, column + 2)); Assert.AreEqual(HitResults.Missed, ship.Fire(row - 1, column)); grid = new Grid(); length = 5; orientation = Grid.Orientation.Vertical; squares = grid.GetFreeStartingSquares(length, orientation); startingSquare = squares[10]; ship = grid.MakeShip(startingSquare, length, orientation); row = startingSquare.Row; column = startingSquare.Column; Assert.AreEqual(HitResults.Missed, ship.Fire(row, column - 1)); Assert.AreEqual(HitResults.Hit, ship.Fire(row + length - 1, column)); Assert.AreEqual(HitResults.Hit, ship.Fire(row + length - 2, column)); Assert.AreEqual(HitResults.Hit, ship.Fire(row + length - 3, column)); Assert.AreEqual(HitResults.Hit, ship.Fire(row + length - 3, column)); Assert.AreEqual(HitResults.Hit, ship.Fire(row + length - 4, column)); Assert.AreEqual(HitResults.Sunk, ship.Fire(row + length - 5, column)); Assert.AreEqual(HitResults.Sunk, ship.Fire(row + length - 5, column)); Assert.AreEqual(HitResults.Sunk, ship.Fire(row + length - 4, column)); }