예제 #1
0
        public void On_New_Game_Initialize_Three_Ships()
        {
            var randomGeneratorMock = new Mock <IRandomGenerator>();

            randomGeneratorMock
            .SetupSequence(it => it.GetRandomBoolean())
            .Returns(true).Returns(true).Returns(false);
            randomGeneratorMock
            .SetupSequence(it => it.GetRandomNumber(0, ROWS))
            .Returns(1).Returns(3);
            randomGeneratorMock
            .SetupSequence(it => it.GetRandomNumber(0, COLUMNS - BATTLESHIP_SIZE))
            .Returns(1);
            randomGeneratorMock
            .Setup(it => it.GetRandomNumber(0, COLUMNS - DESTROYER_SIZE))
            .Returns(3);
            randomGeneratorMock
            .SetupSequence(it => it.GetRandomNumber(0, ROWS - DESTROYER_SIZE))
            .Returns(5);
            randomGeneratorMock
            .Setup(it => it.GetRandomNumber(0, COLUMNS))
            .Returns(5);

            var battleShipGame = new BattleShipGame(GetGrid(), randomGeneratorMock.Object);

            battleShipGame.AddShip(new Ship(BATTLESHIP_SIZE, ShipType.BattleShip));
            battleShipGame.AddShip(new Ship(DESTROYER_SIZE, ShipType.Destroyer));
            battleShipGame.AddShip(new Ship(DESTROYER_SIZE, ShipType.Destroyer));
            battleShipGame.NewGame();

            // Battle Ship
            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]);

            // First Destroyer
            Assert.True(battleShipGame.Grid.Matrix[3, 3]);
            Assert.True(battleShipGame.Grid.Matrix[3, 4]);
            Assert.True(battleShipGame.Grid.Matrix[3, 5]);
            Assert.True(battleShipGame.Grid.Matrix[3, 6]);

            // Second Destroyer
            Assert.True(battleShipGame.Grid.Matrix[5, 5]);
            Assert.True(battleShipGame.Grid.Matrix[6, 5]);
            Assert.True(battleShipGame.Grid.Matrix[7, 5]);
            Assert.True(battleShipGame.Grid.Matrix[8, 5]);
        }
예제 #2
0
        public void Can_Add_Ship()
        {
            var ship           = new Ship(DESTROYER_SIZE, ShipType.Destroyer);
            var battleShipGame = new BattleShipGame(GetGrid(), new Mock <IRandomGenerator>().Object);

            battleShipGame.AddShip(ship);

            Assert.Single(battleShipGame.Ships);
        }