public void Shoot_EmptyCell_ToShooted_Test() { //arrange Game _Game = new Game(); _Game.Stage = GameStage.Playing; EnemyBattleField _EBF = _Game.EnemyBattleField; UserBattleField _UBF = _Game.UserBattleField; _Game.CurrentActor = Actor.User; _EBF.Boats = new List <Boat>(); _UBF.Boats = new List <Boat>(); Random r = new Random(); int _cellNumber = r.Next(100); int x = (int)Math.Floor((double)_cellNumber / 10); int y = _cellNumber % 10; Cell _cell = _EBF.Cells[x, y]; _cell.Style = CellStyle.Empty; //act _cell.Shoot(); //assert Assert.AreEqual(_cell.Style, CellStyle.Shooted); Assert.AreEqual(_cell.IsInvisible, false); }
public void Boat_Test() { //arrange Game _Game = new Game(); UserBattleField _UBF = _Game.UserBattleField; _UBF.Boats = new List <Boat>(); List <Cell> _listCells = new List <Cell> { new Cell(0, 0, _UBF), new Cell(0, 1, _UBF), new Cell(0, 2, _UBF) }; //act Boat _boat = new Boat(_listCells); //assert Assert.IsNotNull(_boat); foreach (var cell in _boat.Cells) { Assert.IsNotNull(cell.ParentBoat); } Assert.AreEqual(_boat.State, BoatState.Healthy); Assert.AreEqual(_boat.Type, BoatType.Cruiser); }
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(); } }
public void Shoot_WoundedBoat_ToDead_Test() { //arrange Game _Game = new Game(); _Game.Stage = GameStage.Playing; EnemyBattleField _EBF = _Game.EnemyBattleField; UserBattleField _UBF = _Game.UserBattleField; _Game.CurrentActor = Actor.User; _EBF.Boats = new List <Boat>(); Boat _boat = new Boat( new List <Cell> { new Cell(0, 0, _EBF), new Cell(0, 1, _EBF), new Cell(0, 2, _EBF), new Cell(0, 3, _EBF) }); _boat.State = BoatState.Wounded; foreach (var cell in _boat.Cells) { cell.Style = CellStyle.WoundedCell; } _EBF.Cells[0, 0] = _boat.Cells[0]; _EBF.Cells[0, 1] = _boat.Cells[1]; _EBF.Cells[0, 2] = _boat.Cells[2]; _EBF.Cells[0, 3] = _boat.Cells[3]; _UBF.Boats = new List <Boat>(); Random r = new Random(); int _cellNumber = r.Next(_boat.Cells.Count); Cell _cell = _boat.Cells[_cellNumber]; _cell.Style = CellStyle.HealthyCell; //act _boat.Shoot(_cell); //assert Assert.AreEqual(_boat.State, BoatState.Dead); foreach (var cell in _boat.Cells) { Assert.AreEqual(cell.Style, CellStyle.DeadCell); } }
public void CheckArrangement_NullBoats_Test() { //arrange Game _Game = new Game(); UserBattleField _UBF = _Game.UserBattleField; string _errorMsg; //act bool _result = _UBF.CheckArrangement(out _errorMsg); //assert }
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(); } }
public void ParseArrangement_BoatsTouch_Test() { //arrange Game _Game = new Game(); UserBattleField _UBF = _Game.UserBattleField; foreach (var coordinates in _CellsCoordinates_BoatsTouch) { _UBF.Cells[coordinates.Item1, coordinates.Item2].DrawCell(); } //act _UBF.ParseArrangement(); //assert Assert.IsNotNull(_UBF.Boats); Assert.AreNotEqual(_UBF.Boats.Count, 10); }
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); }
public void DrawCell_Playing_Test() { //arrange Game _Game = new Game(); _Game.Stage = GameStage.Playing; UserBattleField _BF = _Game.UserBattleField; Random r = new Random(); int _cellNumber = r.Next(100); int x = (int)Math.Floor((double)_cellNumber / 10); int y = _cellNumber % 10; Cell _cell = _BF.Cells[x, y]; //act _cell.DrawCell(); //assert Assert.AreEqual(_cell.Style, CellStyle.Empty); Assert.AreEqual(_cell.IsInvisible, false); }
public void ParseArrangement_CorrectlyFilled_Test() { //arrange Game _Game = new Game(); UserBattleField _UBF = _Game.UserBattleField; foreach (var coordinates in _CellsCoordinates_CorrectlyFilled) { _UBF.Cells[coordinates.Item1, coordinates.Item2].DrawCell(); } //act _UBF.ParseArrangement(); //assert Assert.IsNotNull(_UBF.Boats); Assert.AreEqual(_UBF.Boats.Count, 10); int _BattleshipCount = _UBF.Boats.Count(b => b.Type == BoatType.Battleship); Assert.AreEqual(_BattleshipCount, 1); int _CruiserCount = _UBF.Boats.Count(b => b.Type == BoatType.Cruiser); Assert.AreEqual(_CruiserCount, 2); int _DestroyerCount = _UBF.Boats.Count(b => b.Type == BoatType.Destroyer); Assert.AreEqual(_DestroyerCount, 3); int _TorpedoboatCount = _UBF.Boats.Count(b => b.Type == BoatType.Torpedoboat); Assert.AreEqual(_TorpedoboatCount, 4); }
public void RemoveCell_Arrange_Test() { //arrange Game _Game = new Game(); _Game.Stage = GameStage.BoatsArrange; UserBattleField _BF = _Game.UserBattleField; Random r = new Random(); int _cellNumber = r.Next(100); int x = (int)Math.Floor((double)_cellNumber / 10); int y = _cellNumber % 10; Cell _cell = _BF.Cells[x, y]; _cell.Style = CellStyle.HealthyCell; //act _cell.RemoveCell(); //assert Assert.AreEqual(_cell.Style, CellStyle.Empty); Assert.AreEqual(_cell.IsInvisible, false); }
public void Shoot_HealthyCell_ToDead_Test() { //arrange Game _Game = new Game(); _Game.Stage = GameStage.Playing; EnemyBattleField _EBF = _Game.EnemyBattleField; UserBattleField _UBF = _Game.UserBattleField; _Game.CurrentActor = Actor.User; _EBF.Boats = new List <Boat>(); Boat _boat = new Boat( new List <Cell> { new Cell(5, 8, _EBF) }); _boat.State = BoatState.Healthy; _boat.Cells[0].Style = CellStyle.HealthyCell; _EBF.Cells[5, 8] = _boat.Cells[0]; _UBF.Boats = new List <Boat>(); Cell _cell = _boat.Cells[0]; //act _cell.Shoot(); //assert Assert.AreEqual(_cell.Style, CellStyle.DeadCell); Assert.AreEqual(_cell.IsInvisible, false); }
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); }
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); }