Esempio n. 1
0
        public void IsThereAnyLiveElementOnTheEmptyMapTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>());

            map.RenderMap();
            Assert.IsFalse(map.IsThereAnyLiveElement(), "There is any live element");
        }
Esempio n. 2
0
        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");
        }
Esempio n. 3
0
        public void UserInterfaceCommunicationTest()
        {
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            FakeMap           map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });

            map.RenderMap();
            Player player           = new Player(map);
            int    hitResult        = 0;
            int    hitAndSinkResult = 0;
            Game   game             = new Game(player, fakeUserInterface);

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    game.NextTurn(i, j);
                    if (fakeUserInterface.Reuslt is HitResult)
                    {
                        hitResult++;
                    }

                    if (fakeUserInterface.Reuslt is HitAndSinksResult)
                    {
                        hitAndSinkResult++;
                    }
                }
            }

            Assert.IsTrue(hitResult == 9 && hitAndSinkResult == 3, "The User interface got wrong information");
        }
Esempio n. 4
0
        public void IsThereAnyLiveElementOnTheEmptyMapTest()
        {
            FakeMap map = new FakeMap(3, 1, new List <LiveElement>()
            {
            });
            Player player = new Player(map);

            Assert.IsFalse(player.IsThereAnyLiveElement(), "There is any live element");
        }
Esempio n. 5
0
        public void RenderTooSmallMapExceptionTest()
        {
            FakeMap map = new FakeMap(1, new List <LiveElement>()
            {
                new FakeShip()
            });

            map.RenderMap();
        }
Esempio n. 6
0
        public void IsThereAnyLiveElementOnTheMapWithoutRenderTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip()
            });

            Assert.IsTrue(map.IsThereAnyLiveElement(), "There is not any live element");
        }
Esempio n. 7
0
        public void IsThereAnyLiveElementOnTheFullMapTest()
        {
            FakeMap map = new FakeMap(3, 1, new List <LiveElement>()
            {
                new FakeShip()
            });
            Player player = new Player(map);

            Assert.IsTrue(player.IsThereAnyLiveElement(), "There is not any live element");
        }
Esempio n. 8
0
        public void GetMapPlayerTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip()
            });

            map.RenderMap();
            Player player = new Player(map);

            Field[,] fields = player.GetMap();
            Assert.AreEqual(9, fields.GetLength(0) * fields.GetLength(1), "The map is incorrect");
        }
Esempio n. 9
0
        public void CheckRenderMapWithoutPrepareTest()
        {
            FakeMap map = new FakeMap(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();
            Assert.IsTrue(fakeUserInterface.RenderMapDone && fakeUserInterface.PrepareGameDone == false, "Prepare map is not working correctly");
        }
Esempio n. 10
0
        public void CheckRenderMapOnUserInterfaceConnectionWhenEverythingIsOKTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip()
            });
            Player            player            = new Player(map);
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            Game game = new Game(player, fakeUserInterface);

            game.RenderMap();
            Assert.IsTrue(fakeUserInterface.RenderMapDone, "The Render map has not worked");
        }
Esempio n. 11
0
        public void NotYetWinnerTest()
        {
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            FakeMap           map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });

            map.RenderMap();
            Player player = new Player(map);
            Game   game   = new Game(player, fakeUserInterface);

            Assert.IsFalse(fakeUserInterface.Winner, "The player is winner");
        }
Esempio n. 12
0
        public void CheckRenderMapOnUserInterfaceAfterHitAndRenderTest()
        {
            FakeMap map = new FakeMap(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);
            int  point = 0;

            game.NextTurn(point, point);
            game.RenderMap();
            Assert.AreEqual(Water.DEFAULT_WATER_FILENAME, map.Fields[point, point].GetIconToElement(), "The icon of object is incorrect rendered");
        }
Esempio n. 13
0
        public void CheckErrorUserInterfaceConnectionWhenEverythingIsOKTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip()
            });

            map.RenderMap();
            Player            player            = new Player(map);
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            Game game = new Game(player, fakeUserInterface);

            game.NextTurn(0, 0);
            Assert.IsFalse(fakeUserInterface.ShowErrorDone, "The error was displayed");
        }
Esempio n. 14
0
        public void Shoot16TimesToMapTest()
        {
            FakeMap map = new FakeMap(4, new List <LiveElement>());

            map.RenderMap();
            Player player = new Player(map);

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    player.Shoot(i, j);
                }
            }
            Assert.AreEqual(16, player.Steps, "Steps on the player is not working correctly");
        }
Esempio n. 15
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");
                    }
                }
            }
        }
Esempio n. 16
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");
                    }
                }
            }
        }
Esempio n. 17
0
        public void RenderMapTest()
        {
            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.Fields[i, j] == null)
                    {
                        Assert.Fail("Render map is failed");
                    }
                }
            }
        }
Esempio n. 18
0
        public void IsThereAnyLiveElementOnTheMapWithDeadShipTest()
        {
            FakeShip ship = new FakeShip();

            for (int i = 0; i < FakeShip.DEFAULT_SIZE; i++)
            {
                ship.Hit();
            }

            FakeMap map = new FakeMap(3, new List <LiveElement>()
            {
                ship
            });

            Assert.IsFalse(map.IsThereAnyLiveElement(), "There is any live element");
        }
Esempio n. 19
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");
                    }
                }
            }
        }
Esempio n. 20
0
        public void ShootPlayerOnTheEmptyFieldTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>());

            map.RenderMap();
            Player player = new Player(map);

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    if (player.Shoot(i, j) is MissResult == false)
                    {
                        Assert.Fail("Hit on the map is not working correctly");
                    }
                }
            }
        }
Esempio n. 21
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");
        }
Esempio n. 22
0
        public void ShootToDeadObjectTest()
        {
            FakeMap map = new FakeMap(3, 1, new List <LiveElement>()
            {
                new FakeShip()
            });

            map.RenderMap();
            Player player = new Player(map);

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    player.Shoot(i, j);
                }
            }
            ShootResult hitType = player.Shoot(0, 0);

            Assert.IsTrue(hitType is FieldIsHitAlreadyResult, "The Hit type is incorrectly");
        }
Esempio n. 23
0
        public void WinnerTest()
        {
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            FakeMap           map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });

            map.RenderMap();
            Player player = new Player(map);
            Game   game   = new Game(player, fakeUserInterface);

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    game.NextTurn(i, j);
                }
            }
            Assert.IsTrue(fakeUserInterface.Winner, "The player is not winner");
        }
Esempio n. 24
0
        public void PlayTwoTimesAndCheckBestScorePlayerTest()
        {
            FakeMap map = new FakeMap(4, new List <LiveElement>());

            map.RenderMap();
            Player player = new Player(map);

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    player.Shoot(i, j);
                }
            }
            player.SetBestSteps();
            player.RenderMap();
            player.Shoot(0, 0);
            player.SetBestSteps();

            Assert.AreEqual(1, player.BestSteps, "Best steps on the player is not working correctly");
        }
Esempio n. 25
0
        public void ShootPlayerTest()
        {
            FakeMap map = new FakeMap(3, new List <LiveElement>()
            {
                new FakeShip(), new FakeShip(), new FakeShip()
            });

            map.RenderMap();
            Player player = new Player(map);

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    ShootResult result = player.Shoot(i, j);
                    if (result is HitResult == false)
                    {
                        Assert.Fail("Shoot is not working correctly");
                    }
                }
            }
        }
Esempio n. 26
0
        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");
        }
Esempio n. 27
0
        public void TheBestScoreOfPlayerTest()
        {
            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();

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    game.NextTurn(i, j);
                }
            }

            Assert.IsTrue(player.BestSteps > 0, "The best score of player is wrong");
        }
Esempio n. 28
0
        public void CheckStepsPlayerTest()
        {
            FakeMap map = new FakeMap(1, 3, new List <LiveElement>()
            {
                new FakeShip()
            });
            Player            player            = new Player(map);
            FakeUserInterface fakeUserInterface = new FakeUserInterface();
            Game game = new Game(player, fakeUserInterface);

            game.RenderMap();

            for (int i = 0; i < map.Fields.GetLength(0); i++)
            {
                for (int j = 0; j < map.Fields.GetLength(1); j++)
                {
                    game.NextTurn(i, j);
                }
            }

            Assert.IsTrue(fakeUserInterface.CurrenctScore == 3 && fakeUserInterface.YourRecord == 3, "Score and The best score is not correctly");
        }