public void Should_Sink_OnlyWhenAllCellsDamaged()
        {
            var battleship = new Battleship(4, 1);

            for (var i = 0; i < 4; i++)
            {
                Assert.IsFalse(battleship.IsSunk());
                battleship.InflictDamageAt(new Coord {
                    X = i, Y = 0
                });
            }
            Assert.IsTrue(battleship.IsSunk());
        }
        public void Should_NotSink_WhenOneCellRepeatedlyDamaged()
        {
            var battleship = new Battleship(4, 1);

            for (var i = 0; i < 4; i++)
            {
                Assert.IsFalse(battleship.IsSunk());
                battleship.InflictDamageAt(new Coord {
                    X = 0, Y = 0
                });
            }
            Assert.IsFalse(battleship.IsSunk());
        }
Ejemplo n.º 3
0
        public void TestBattleshipHit()
        {
            List <Coordinate> battleshipCoords = new List <Coordinate> {
                new Coordinate(0, 0), new Coordinate(0, 1), new Coordinate(0, 2)
            };
            Battleship battleship = new Battleship(battleshipCoords);

            // Test hitting battleship with invalid coordinates
            Assert.ThrowsException <ArgumentException>(() => battleship.Hit(new Coordinate(-1, -1)));
            Assert.ThrowsException <ArgumentException>(() => battleship.Hit(new Coordinate(0, 3)));
            Assert.ThrowsException <ArgumentException>(() => battleship.Hit(new Coordinate(1, 0)));
            battleship.Hit(new Coordinate(0, 0));
            battleship.Hit(new Coordinate(0, 1));
            battleship.Hit(new Coordinate(0, 2));

            Assert.IsTrue(battleship.IsSunk());
        }