public void TestDefaults() { var game = new BattleshipGameBoard(); Assertions.AssertThat(game.SizeX).IsEqualTo(10); Assertions.AssertThat(game.SizeY).IsEqualTo(10); }
public void TestCustomGameSize() { var game = new BattleshipGameBoard(2, 3); Assertions.AssertThat(game.SizeX).IsEqualTo(2); Assertions.AssertThat(game.SizeY).IsEqualTo(3); }
public void TestAttackHit() { var game = new BattleshipGameBoard() .PlaceShip(new Destroyer(), 0, 0, Facing.Horizontal) .PlaceShip(new Carrier(), 0, 1, Facing.Vertical); Assertions.AssertThat(game.Attack(0, 0).Hit).IsTrue(); }
public void TestGameOverWithUndamagedFleet() { var game = new BattleshipGameBoard() .PlaceShip(new Destroyer(), 0, 0, Facing.Horizontal) .PlaceShip(new Carrier(), 0, 1, Facing.Vertical); Assertions.AssertThat(game.GameOver).IsFalse(); }
public void TestHullLengths() { Assertions.AssertThat(new Carrier().Length).IsEqualTo(5); Assertions.AssertThat(new Battleship().Length).IsEqualTo(4); Assertions.AssertThat(new Cruiser().Length).IsEqualTo(3); Assertions.AssertThat(new Submarine().Length).IsEqualTo(3); Assertions.AssertThat(new Destroyer().Length).IsEqualTo(2); }
public void TestAttackTwice() { var game = new BattleshipGameBoard(); game.Attack(0, 0); Assertions.AssertThat(() => game.Attack(0, 0)) .ThrowsException(typeof(ArgumentException)) .WithMessageContaining("already"); }
public void TestPlaceShipPerpendicularCollision() { var game = new BattleshipGameBoard(); game.PlaceShip(new Carrier(), 0, 1, Facing.Horizontal); Assertions.AssertThat(() => { game.PlaceShip(new Cruiser(), 1, 0, Facing.Vertical); }) .ThrowsException(typeof(ArgumentException)) .WithMessageContaining("collide"); }
public void TestConstructDefaults() { var ship = new BaseShip(10); Assertions.AssertThat(ship.Length).IsEqualTo(10); Assertions.AssertThat(ship.Damage) .HasSize(10) .AllSatisfy(x => x == false); Assertions.AssertThat(ship.IsSunk).IsFalse(); }
public void TestGetBoundingBoxForNorthSouthHeading() { var nsCruiser = new BattleshipGameBoard.FleetEntry( new Cruiser(), 3, 4, Facing.Vertical ).GetBoundingBox(); Assertions.AssertThat(nsCruiser.Left).IsEqualTo(3); Assertions.AssertThat(nsCruiser.Top).IsEqualTo(4); Assertions.AssertThat(nsCruiser.Width).IsEqualTo(1); Assertions.AssertThat(nsCruiser.Height).IsEqualTo(3); }
public void TestGetBoundingBoxForEastWestHeading() { var ewBattleShip = new BattleshipGameBoard.FleetEntry( new Battleship(), 3, 4, Facing.Horizontal ).GetBoundingBox(); Assertions.AssertThat(ewBattleShip.Left).IsEqualTo(3); Assertions.AssertThat(ewBattleShip.Top).IsEqualTo(4); Assertions.AssertThat(ewBattleShip.Width).IsEqualTo(4); Assertions.AssertThat(ewBattleShip.Height).IsEqualTo(1); }
public void TestGameGridIsInitialized() { var game = new BattleshipGameBoard(); for (int x = 0; x < game.SizeX; x++) { for (int y = 0; y < game.SizeY; y++) { var cell = game.Grid[x, y]; Assertions.AssertThat(cell).IsFalse(); } } }
public void TestGameOverWithSunkFleet() { var game = new BattleshipGameBoard() .PlaceShip(new Destroyer(), 0, 0, Facing.Horizontal) .PlaceShip(new Carrier(), 1, 1, Facing.Vertical); game.Attack(0, 0); game.Attack(1, 0); game.Attack(1, 1); game.Attack(1, 2); game.Attack(1, 3); game.Attack(1, 4); game.Attack(1, 5); Assertions.AssertThat(game.GameOver).IsTrue(); }
public void TestApplyDamage() { var ship = new BaseShip(3); Assertions.AssertThat(ship.Damage).ContainsExactly(false, false, false); ship.ApplyDamage(0); Assertions.AssertThat(ship.Damage).ContainsExactly(true, false, false); Assertions.AssertThat(ship.IsSunk).IsFalse(); ship.ApplyDamage(2); Assertions.AssertThat(ship.Damage).ContainsExactly(true, false, true); Assertions.AssertThat(ship.IsSunk).IsFalse(); ship.ApplyDamage(1); Assertions.AssertThat(ship.Damage).ContainsExactly(true, true, true); Assertions.AssertThat(ship.IsSunk).IsTrue(); }
public void TestGameOverWithNoFleet() { var game = new BattleshipGameBoard(); Assertions.AssertThat(game.GameOver).IsFalse(); }