Пример #1
0
        public void ShootToUserBFAutomatically_WoundedBF_Test()
        {
            //arrange
            Game _Game = new Game();

            _Game.CurrentActor = Actor.Computer;
            UserBattleField  _UBF = _Game.UserBattleField;
            EnemyBattleField _EBF = _Game.EnemyBattleField;

            _EBF.Boats = new List <Boat>();

            foreach (var coordinates in _CellsCoordinates_CorrectlyFilled)
            {
                _UBF.Cells[coordinates.Item1, coordinates.Item2].DrawCell();
            }

            _UBF.ParseArrangement();
            string err;

            _UBF.CheckArrangement(out err);

            Random      r      = new Random();
            List <Boat> _boats = _UBF.Boats.Where(b => b.Cells.Count > 1).ToList();
            int         index1 = r.Next(1, _boats.Count) - 1;
            Boat        _boat  = _boats[index1];

            int  index2       = r.Next(1, _boat.Cells.Count) - 1;
            Cell _cellToShoot = _boat.Cells[index2];

            _boat.Shoot(_cellToShoot); //now we have a wounded boat

            //act
            _Game.ShootToUserBFAutomatically();

            //assert
            //Computer had to try to finish him
            List <Cell> _potentiallyshootedCells =
                _UBF.Cells.Cast <Cell>().ToList().
                Where(c =>
                      (c.x == _cellToShoot.x &&
                       (c.y == (_cellToShoot.y - 1) || c.y == (_cellToShoot.y + 1))) ||

                      (c.y == _cellToShoot.y &&
                       (c.x == (_cellToShoot.x - 1) || c.x == (_cellToShoot.x + 1)))
                      ).ToList();

            if (_potentiallyshootedCells.Where(c => (c.IsShooted == true)).Count() != 1)
            {
                Assert.Fail();
            }
            if (!_potentiallyshootedCells.Any(c =>
                                              (c.Style == CellStyle.Shooted ||
                                               c.Style == CellStyle.WoundedCell ||
                                               c.Style == CellStyle.DeadCell)))
            {
                Assert.Fail();
            }
        }
Пример #2
0
        public void CheckArrangement_NullBoats_Test()
        {
            //arrange
            Game            _Game = new Game();
            UserBattleField _UBF  = _Game.UserBattleField;

            string _errorMsg;

            //act
            bool _result = _UBF.CheckArrangement(out _errorMsg);

            //assert
        }
Пример #3
0
        public void ShootToUserBFAutomatically_NewBF_Test()
        {
            //arrange
            Game _Game = new Game();

            _Game.CurrentActor = Actor.Computer;
            UserBattleField  _UBF = _Game.UserBattleField;
            EnemyBattleField _EBF = _Game.EnemyBattleField;

            _EBF.Boats = new List <Boat>();

            foreach (var coordinates in _CellsCoordinates_CorrectlyFilled)
            {
                _UBF.Cells[coordinates.Item1, coordinates.Item2].DrawCell();
            }

            _UBF.ParseArrangement();
            string err;

            _UBF.CheckArrangement(out err);

            //act
            _Game.ShootToUserBFAutomatically();

            //assert
            List <Cell> _shootedCells =
                _UBF.Cells.Cast <Cell>().ToList().
                Where(c => (c.IsShooted == true)).ToList();


            Assert.AreEqual(_shootedCells.Count, 1);

            if (_shootedCells.Count == 1)
            {
                Assert.AreEqual(_shootedCells[0].Style, CellStyle.Shooted);
            }
            else if (_shootedCells.Count > 1)
            {
                Assert.AreEqual(_shootedCells.Where(c => c.Style == CellStyle.Shooted).Count(), 1);
            }
            else
            {
                Assert.Fail();
            }
        }
Пример #4
0
        public void CheckArrangement_TooLongBoat_Test()
        {
            //arrange
            Game            _Game = new Game();
            UserBattleField _UBF  = _Game.UserBattleField;

            foreach (var coordinates in _CellsCoordinates_TooLongBoat)
            {
                _UBF.Cells[coordinates.Item1, coordinates.Item2].DrawCell();
            }
            _UBF.ParseArrangement();
            string _errorMsg;

            //act
            bool _result = _UBF.CheckArrangement(out _errorMsg);

            //assert
            Assert.AreEqual(_result, false);
        }
Пример #5
0
        public void IsOver_ComputersShot_True_Test()
        {
            //arrange
            Game _Game = new Game();

            _Game.CurrentActor = Actor.Computer;
            UserBattleField _UBF = _Game.UserBattleField;

            foreach (var coordinates in _CellsCoordinates_CorrectlyFilled)
            {
                _UBF.Cells[coordinates.Item1, coordinates.Item2].DrawCell();
            }

            _UBF.ParseArrangement();
            string err;

            _UBF.CheckArrangement(out err);

            foreach (var boat in _UBF.Boats)
            {
                foreach (var cell in boat.Cells)
                {
                    cell.Style = CellStyle.DeadCell;
                }

                boat.State = BoatState.Dead;
            }

            //act
            bool result = _Game.IsOver();

            //assert
            Assert.AreEqual(result, true);
            Assert.AreEqual(_Game.Result, GameResult.Defeat);
            Assert.AreEqual(_Game.Stage, GameStage.Finished);
        }
Пример #6
0
        public void IsOver_ComputersShot_False_Test()
        {
            //arrange
            Game _Game = new Game();

            _Game.CurrentActor = Actor.Computer;
            UserBattleField _UBF = _Game.UserBattleField;

            foreach (var coordinates in _CellsCoordinates_CorrectlyFilled)
            {
                _UBF.Cells[coordinates.Item1, coordinates.Item2].DrawCell();
            }

            _UBF.ParseArrangement();
            string err;

            _UBF.CheckArrangement(out err);

            //act
            bool result = _Game.IsOver();

            //assert
            Assert.AreEqual(result, false);
        }