コード例 #1
0
ファイル: GameTest.cs プロジェクト: KristopRz/BattleShipLib
        public void RenderMapCheckCorrectlyElementsTest()
        {
            FakeMap map = new FakeMap(4, 3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });
            Player            player            = new Player(map);
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            Game game = new Game(player, fakeUserInterface);

            game.RenderMap();
            int count    = 0;
            int allCount = 0;

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    allCount++;
                    if (map.Hit(i, j) is HitResult)
                    {
                        count++;
                    }
                }
            }

            Assert.IsTrue(allCount == 12 && count == 9, "The map is rendered fail");
        }
コード例 #2
0
        public void HitEmptyFieldBattleMapTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>());

            map.RenderMap();
            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    if (map.Hit(i, j) is MissResult == false)
                    {
                        Assert.Fail("Hit on the map is not working correctly");
                    }
                }
            }
        }
コード例 #3
0
        public void RenderMapCheckWaterTest()
        {
            FakeMap map = this.CreateFakeMap();

            map.RenderMap();
            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    if (map.Hit(i, j) is MissResult)
                    {
                        Assert.Fail("Render map is failed");
                    }
                }
            }
        }
コード例 #4
0
        public void HitBattleMapTest()
        {
            FakeMap map = this.CreateFakeMap();

            map.RenderMap();
            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    ShootResult result = map.Hit(i, j);
                    if (result is HitResult == false)
                    {
                        Assert.Fail("Hit on the map is not working correctly");
                    }
                }
            }
        }
コード例 #5
0
        public void HowManyShipsAreThereTest()
        {
            FakeMap map   = this.CreateFakeMap();
            int     count = 0;

            map.RenderMap();
            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    if (map.Hit(i, j) is HitAndSinksResult)
                    {
                        count++;
                    }
                }
            }
            Assert.AreEqual(3, count, "Number of ships is incorrect");
        }
コード例 #6
0
ファイル: PlayerTest.cs プロジェクト: KristopRz/BattleShipLib
        public void RenderMapTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip()
            });

            map.RenderMap();
            int count = 0;

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    if (map.Hit(i, j) is HitResult)
                    {
                        count++;
                    }
                }
            }
            Assert.AreEqual(6, count, "Render map is failed");
        }