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 IsOver_UsersShot_True_Test() { //arrange Game _Game = new Game(); _Game.CurrentActor = Actor.User; EnemyBattleField _EBF = _Game.EnemyBattleField; _EBF.ArrangeAutomatically(); foreach (var boat in _EBF.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.Victory); Assert.AreEqual(_Game.Stage, GameStage.Finished); }
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 RemoveFog_Test() { //arrange Game _Game = new Game(); EnemyBattleField _EBF = _Game.EnemyBattleField; //act _EBF.RemoveFog(); int _InvisibleCellsQuantity = _EBF.Cells.Cast <Cell>().ToList(). Count(c => (c.IsInvisible == true)); Assert.AreEqual(_InvisibleCellsQuantity, 0); }
public void IsOver_UsersShot_False_Test() { //arrange Game _Game = new Game(); _Game.CurrentActor = Actor.User; EnemyBattleField _EBF = _Game.EnemyBattleField; _EBF.ArrangeAutomatically(); //act bool result = _Game.IsOver(); //assert Assert.AreEqual(result, false); }
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 ArrangeAutomatically_Test() { //arrange Game _Game = new Game(); EnemyBattleField _EBF = _Game.EnemyBattleField; //act _EBF.ArrangeAutomatically(); //assert Assert.IsNotNull(_EBF.Boats); Assert.AreEqual(_EBF.Boats.Count, 10); int _TooLongCount = _EBF.Boats.Count(a => a.Cells.Count > 4); Assert.AreEqual(_TooLongCount, 0); int _BattlecruisersCount = _EBF.Boats.Count(a => a.Cells.Count == 4); Assert.AreEqual(_BattlecruisersCount, 1); int _CruisersCount = _EBF.Boats.Count(a => a.Cells.Count == 3); Assert.AreEqual(_CruisersCount, 2); int _DestroyersCount = _EBF.Boats.Count(a => a.Cells.Count == 2); Assert.AreEqual(_DestroyersCount, 3); int _TorpedoboatsCount = _EBF.Boats.Count(a => a.Cells.Count == 1); Assert.AreEqual(_TorpedoboatsCount, 4); //boats bend or touch if (!_EBF.Boats.All(b => (b.Cells.Select(c => c.x).Distinct().Count() == 1) || (b.Cells.Select(c => c.y).Distinct().Count() == 1) ) ) { Assert.Fail(); } }
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 SurroundBoat_InMiddle_Arranged_Test() { //arrange Game _Game = new Game(); EnemyBattleField _EBF = _Game.EnemyBattleField; _EBF.Boats = new List <Boat>(); Boat _boat = new Boat( new List <Cell> { new Cell(3, 5, _EBF) }); _EBF.Boats.Add(_boat); _boat.State = BoatState.Healthy; _boat.Cells[0].Style = CellStyle.HealthyCell; _EBF.Cells[3, 5] = _boat.Cells[0]; //act _EBF.SurroundBoat(_boat, CellStyle.Empty, true); //assert int minX = _boat.Cells.Min(c => c.x) - 1; int maxX = _boat.Cells.Max(c => c.x) + 1; int minY = _boat.Cells.Min(c => c.y) - 1; int maxY = _boat.Cells.Max(c => c.y) + 1; //asserts that neigbours marked correctly List <Cell> _neigbours = _EBF.Cells.Cast <Cell>().ToList(). Where( c => c.x >= minX && c.x <= maxX && c.y >= minY && c.y <= maxY && !(((c.x > minX) && (c.x < maxX)) && ((c.y > minY) && (c.y < maxY))) ).ToList(); foreach (var cell in _neigbours) { Assert.AreEqual(cell.IsInvisible, true); Assert.AreEqual(cell.IsSafeZone, true); Assert.AreEqual(cell.Style, CellStyle.Empty); } //asserts that cells of boat weren't changed foreach (var cell in _boat.Cells) { Assert.AreEqual(cell.Style, CellStyle.HealthyCell); Assert.AreEqual(cell.IsInvisible, true); } //asserts that other calles of BF weren't changed List <Cell> _others = _EBF.Cells.Cast <Cell>().ToList(). Where( c => !(_boat.Cells.Contains(c)) && !(_neigbours.Contains(c)) ).ToList(); foreach (var cell in _others) { Assert.AreEqual(cell.IsInvisible, true); Assert.AreEqual(cell.Style, CellStyle.Empty); } //asserts that priority zone created List <Cell> _friendlyCells = _EBF.Cells.Cast <Cell>().ToList(). Where( c => c.x >= (minX - 1) && c.x <= (maxX + 1) && c.y >= (minY - 1) && c.y <= (maxY + 1) && !(((c.x > minX - 1) && (c.x < maxX + 1)) && ((c.y > minY - 1) && (c.y < maxY + 1))) ).ToList(); foreach (var cell in _friendlyCells) { Assert.AreEqual(cell.IsBoatsFriendlyZone, true); } }
public void SurroundBoat_NearWall_Shooted_Test() { //arrange Game _Game = new Game(); EnemyBattleField _EBF = _Game.EnemyBattleField; _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) }); _EBF.Boats.Add(_boat); _boat.State = BoatState.Healthy; foreach (var cell in _boat.Cells) { cell.Style = CellStyle.HealthyCell; } _EBF.Cells[0, 0] = _boat.Cells[0]; _EBF.Cells[0, 1] = _boat.Cells[1]; _EBF.Cells[0, 2] = _boat.Cells[2]; //act _EBF.SurroundBoat(_boat, CellStyle.Shooted, false); //assert int minX = _boat.Cells.Min(c => c.x) - 1; int maxX = _boat.Cells.Max(c => c.x) + 1; int minY = _boat.Cells.Min(c => c.y) - 1; int maxY = _boat.Cells.Max(c => c.y) + 1; //asserts that neigbours marked correctly List <Cell> _neigbours = _EBF.Cells.Cast <Cell>().ToList(). Where( c => c.x >= minX && c.x <= maxX && c.y >= minY && c.y <= maxY && !(((c.x > minX) && (c.x < maxX)) && ((c.y > minY) && (c.y < maxY))) ).ToList(); foreach (var cell in _neigbours) { Assert.AreEqual(cell.IsInvisible, false); Assert.AreEqual(cell.Style, CellStyle.Shooted); } //asserts that cells of boat weren't changed foreach (var cell in _boat.Cells) { Assert.AreEqual(cell.Style, CellStyle.HealthyCell); } //asserts that other calles of BF weren't changed List <Cell> _others = _EBF.Cells.Cast <Cell>().ToList(). Where( c => !(_boat.Cells.Contains(c)) && !(_neigbours.Contains(c)) ).ToList(); foreach (var cell in _others) { Assert.AreEqual(cell.IsInvisible, true); Assert.AreEqual(cell.Style, CellStyle.Empty); } }