public void Can_Retry_Generating_Ship_If_Ship_Was_On_Top_Of_Another_Ship() { var randomGeneratorMock = new Mock <IRandomGenerator>(); randomGeneratorMock .SetupSequence(it => it.GetRandomBoolean()) .Returns(false).Returns(false); randomGeneratorMock .SetupSequence(it => it.GetRandomNumber(0, ROWS - BATTLESHIP_SIZE)) .Returns(1).Returns(2); // 2nd time we return a 2 since first row contains a ship randomGeneratorMock .SetupSequence(it => it.GetRandomNumber(0, COLUMNS)) .Returns(1).Returns(1); var grid = GetGrid(); var ship = new Ship(BATTLESHIP_SIZE, ShipType.BattleShip); ship.SetPositions(new Point(1, 1), new Point(1, 5)); grid.AddShip(ship); var battleShipGame = new BattleShipGame(grid, randomGeneratorMock.Object); battleShipGame.GenerateRandomShipPositions(new Ship(BATTLESHIP_SIZE, ShipType.BattleShip)); Assert.True(battleShipGame.Grid.Matrix[2, 1]); Assert.True(battleShipGame.Grid.Matrix[3, 1]); Assert.True(battleShipGame.Grid.Matrix[4, 1]); Assert.True(battleShipGame.Grid.Matrix[5, 1]); Assert.True(battleShipGame.Grid.Matrix[6, 1]); }
public void Can_Generate_Random_Horizontal_Ship() { var randomGeneratorMock = new Mock <IRandomGenerator>(); randomGeneratorMock .Setup(it => it.GetRandomBoolean()) .Returns(true); // Setup random row randomGeneratorMock .Setup(it => it.GetRandomNumber(0, ROWS)) .Returns(1); // Setup column with ROWS - ship size in order to exclude invalid ships randomGeneratorMock .Setup(it => it.GetRandomNumber(0, COLUMNS - BATTLESHIP_SIZE)) .Returns(1); var battleShipGame = new BattleShipGame(GetGrid(), randomGeneratorMock.Object); battleShipGame.GenerateRandomShipPositions(new Ship(BATTLESHIP_SIZE, ShipType.BattleShip)); Assert.True(battleShipGame.Grid.Matrix[1, 1]); Assert.True(battleShipGame.Grid.Matrix[1, 2]); Assert.True(battleShipGame.Grid.Matrix[1, 3]); Assert.True(battleShipGame.Grid.Matrix[1, 4]); Assert.True(battleShipGame.Grid.Matrix[1, 5]); }
public void Can_Generate_Random_Vertical_Ship() { var randomGeneratorMock = new Mock <IRandomGenerator>(); randomGeneratorMock .Setup(it => it.GetRandomBoolean()) .Returns(false); randomGeneratorMock .Setup(it => it.GetRandomNumber(0, ROWS - BATTLESHIP_SIZE)) .Returns(1); randomGeneratorMock .Setup(it => it.GetRandomNumber(0, COLUMNS)) .Returns(1); var battleShipGame = new BattleShipGame(GetGrid(), randomGeneratorMock.Object); battleShipGame.GenerateRandomShipPositions(new Ship(BATTLESHIP_SIZE, ShipType.BattleShip)); Assert.True(battleShipGame.Grid.Matrix[1, 1]); Assert.True(battleShipGame.Grid.Matrix[2, 1]); Assert.True(battleShipGame.Grid.Matrix[3, 1]); Assert.True(battleShipGame.Grid.Matrix[4, 1]); Assert.True(battleShipGame.Grid.Matrix[5, 1]); }