public void WhenShipAlreadySunk_ShouldNotRecordShot() { var cb = new TestCoordinateBoundary(10, 10); var ships = new [] { CreateShip("a1", cb), CreateShip("g1", cb) }; var fleet = new Fleet(ships); fleet.AcceptShot(cb.CoordinateFromInput("a1")); fleet.AcceptShot(cb.CoordinateFromInput("b1")); fleet.AcceptShot(cb.CoordinateFromInput("c1")); fleet.AcceptShot(cb.CoordinateFromInput("d1")); Assert.True(ships[0].IsSunk); Assert.True(fleet.AnyShipOperational); Assert.True(fleet.ShotsRecorded.Any()); Assert.True(fleet.ShotsRecorded.All(x => x.Value == ShotResult.SINK)); fleet.AcceptShot(cb.CoordinateFromInput("a1")); Assert.True(fleet.ShotsRecorded.Last().Value == ShotResult.SINK); Assert.True(fleet.ShotsRecorded.Last().Key.ToString(cb) == "d1"); }
public void WhenAllShipsSunk_ShouldReportNoShipsOperational() { var cb = new TestCoordinateBoundary(10, 10); var ships = new [] { CreateShip("a1", cb) }; var fleet = new Fleet(ships); fleet.AcceptShot(cb.CoordinateFromInput("a1")); fleet.AcceptShot(cb.CoordinateFromInput("b1")); fleet.AcceptShot(cb.CoordinateFromInput("c1")); fleet.AcceptShot(cb.CoordinateFromInput("d1")); Assert.True(ships[0].IsSunk); Assert.False(fleet.AnyShipOperational); }
public void ShouldCreateInvalidHorizontalPosition(string value, ShipSize size) { var cb = new TestCoordinateBoundary(10, 10); var coord = cb.CoordinateFromInput(value); var result = ShipPosition.Horizontal(coord, size); Assert.False(result.IsValid); Assert.Null(result.Coordinates); }
public void ShouldCreateHorizontalCoordinates(string value, ShipSize size) { var cb = new TestCoordinateBoundary(10, 10); var coord = cb.CoordinateFromInput(value); var result = ShipPosition.Horizontal(coord, size); Assert.True(result.IsValid); Assert.NotNull(result.Coordinates); Assert.True(result.Coordinates.Count() == (int)size); }
public void When4BulkheadShipHitOnce_ShouldNotSink() { var cb = new TestCoordinateBoundary(10, 10); var coord = cb.CoordinateFromInput("a1"); var pos = ShipPosition.Horizontal(coord, ShipSize.Destroyer); var ship = new Ship(pos); Assert.False(ship.IsSunk); ship.Hit(coord); Assert.False(ship.IsSunk); }
public void WhenShipHitTwiceAtSameCoords_ShouldNotCountAsHit() { var cb = new TestCoordinateBoundary(10, 10); var coord = cb.CoordinateFromInput("a1"); var pos = ShipPosition.Horizontal(coord, ShipSize.Destroyer); var ship = new Ship(pos); Assert.False(ship.IsSunk); ship.Hit(coord); ship.Hit(new BattleCoordinate(coord.ColumnNumber + 1, coord.RowNumber, coord)); ship.Hit(new BattleCoordinate(coord.ColumnNumber + 2, coord.RowNumber, coord)); ship.Hit(coord); Assert.False(ship.IsSunk); }
public void WhenAllShipBulkheadsHit_ShouldSink() { var cb = new TestCoordinateBoundary(10, 10); var coord = cb.CoordinateFromInput("a1"); var pos = ShipPosition.Horizontal(coord, ShipSize.Destroyer); var ship = new Ship(pos); Assert.False(ship.IsSunk); ship.Hit(coord); ship.Hit(new BattleCoordinate(coord.ColumnNumber + 1, coord.RowNumber, coord)); ship.Hit(new BattleCoordinate(coord.ColumnNumber + 2, coord.RowNumber, coord)); ship.Hit(new BattleCoordinate(coord.ColumnNumber + 3, coord.RowNumber, coord)); Assert.True(ship.IsSunk); }
public void WhenShotAtShip_ShouldRecordShotAsHit() { var cb = new TestCoordinateBoundary(10, 10); var ships = new [] { CreateShip("a1", cb) }; var fleet = new Fleet(ships); fleet.AcceptShot(cb.CoordinateFromInput("b1")); Assert.False(ships[0].IsSunk); Assert.True(fleet.ShotsRecorded.Any()); Assert.True(fleet.ShotsRecorded.Last().Value == ShotResult.HIT); Assert.True(fleet.ShotsRecorded.Last().Key.ToString(cb) == "b1"); }