public BattleshipPlan BattleshipPlan() { var cells = new BattleshipCell[2, 4]; for (var i = 0; i < 4; i++) { cells[0, i] = new BattleshipCell(CellNameBuilder.ToName(0, i), 0, i); cells[1, i] = new BattleshipCell(CellNameBuilder.ToName(1, i), 1, i); } var ship = new Battleship { ShipType = ShipType.Destroyer, Cells = Enumerable.Range(0, 4).Select(e => cells[0, e]).ToArray() }; foreach (var cell in ship.Cells) { cell.Assign(); } return(new BattleshipPlan { Cells = cells, Ships = new [] { ship }, Columns = 2, Rows = 4 }); }
public void Should_PlaceShip_ReturnsCorrectPlan_DependsOnGivenInputs() { // Arrange var cells = new BattleshipCell[1, 4]; cells[0, 0] = new BattleshipCell("A1", 0, 0); cells[0, 1] = new BattleshipCell("A2", 0, 1); cells[0, 2] = new BattleshipCell("A3", 0, 2); cells[0, 3] = new BattleshipCell("A4", 0, 3); var sut = new RandomPlacementStrategy(); // Act var actual = sut.PlaceShip(cells, new ShipTypeDefinition { ShipType = ShipType.Destroyer, Length = 4 }); // Assert actual.ShipType.Should().Be(ShipType.Destroyer); actual.Cells.Length.Should().Be(4); actual.Cells.Should().BeEquivalentTo(cells[0, 0], cells[0, 1], cells[0, 2], cells[0, 3]); }