Ejemplo n.º 1
0
        public void TestDefaults()
        {
            var game = new BattleshipGameBoard();

            Assertions.AssertThat(game.SizeX).IsEqualTo(10);
            Assertions.AssertThat(game.SizeY).IsEqualTo(10);
        }
Ejemplo n.º 2
0
        public void TestCustomGameSize()
        {
            var game = new BattleshipGameBoard(2, 3);

            Assertions.AssertThat(game.SizeX).IsEqualTo(2);
            Assertions.AssertThat(game.SizeY).IsEqualTo(3);
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
        public void TestAttackTwice()
        {
            var game = new BattleshipGameBoard();

            game.Attack(0, 0);
            Assertions.AssertThat(() => game.Attack(0, 0))
            .ThrowsException(typeof(ArgumentException))
            .WithMessageContaining("already");
        }
Ejemplo n.º 7
0
        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");
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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();
                }
            }
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
0
        public void TestGameOverWithNoFleet()
        {
            var game = new BattleshipGameBoard();

            Assertions.AssertThat(game.GameOver).IsFalse();
        }