Esempio n. 1
0
        public void NumbersOfAnimals_AddAnimalsFollowCounter_CounterShowsCorrectValues()
        {
            Antelope antelope1 = new Antelope(2, 2)
            {
                XPaygroundCoordinate = 2, YPaygroundCoordinate = 2
            };
            Antelope antelope2 = new Antelope(2, 2)
            {
                XPaygroundCoordinate = 1, YPaygroundCoordinate = 2
            };
            Lion lion = new Lion(2, 2)
            {
                XPaygroundCoordinate = 5, YPaygroundCoordinate = 5
            };

            Assert.Equal(0, _sut.NumbersOfAnimals().Item1);
            Assert.Equal(0, _sut.NumbersOfAnimals().Item2);

            _sut.AddHerbivores(antelope1);
            Assert.Equal(1, _sut.NumbersOfAnimals().Item2);

            _sut.AddHerbivores(antelope2);
            Assert.Equal(2, _sut.NumbersOfAnimals().Item2);

            _sut.AddHunters(lion);
            Assert.Equal(1, _sut.NumbersOfAnimals().Item1);
            Assert.Equal(2, _sut.NumbersOfAnimals().Item2);
        }
        public void Behave_When_AnimalIsCarnivore_And_PredatorInVisionRange_Expect_GetEscapePathCall()
        {
            // Arrange
            var carnivore = new Antelope()
            {
                Coordinates = new Coordinates(0, 1)
            };
            var predator = new Lion()
            {
                Coordinates = new Coordinates(0, 0)
            };
            var animalList = new List <IAnimal> {
                carnivore, predator
            };

            _animalLogicMock
            .Setup(x => x.RemoveDeadAnimals(animalList))
            .Returns(() => animalList);

            _coordinatesLogicMock
            .Setup(x => x.GetPredatorsCoordinatesInVisionRange(carnivore, It.IsAny <List <IAnimal> >()))
            .Returns(() => new List <Coordinates> {
                predator.Coordinates
            });

            // Act
            _movementLogic.Behave(carnivore, animalList);

            // Assert
            _coordinatesLogicMock.Verify(x => x.GetEscapePath(carnivore, It.IsAny <List <Coordinates> >()));
        }
        public void Behave_When_PredatorAndCarnivoreCoordinatesNotEqual_Expect_SameCarnivore()
        {
            // Arrange
            var predator = new Lion()
            {
                Coordinates = new Coordinates(6, 5)
            };
            var carnivore1 = new Antelope()
            {
                Coordinates = new Coordinates(4, 5)
            };
            var carnivore2 = new Antelope()
            {
                Coordinates = new Coordinates(5, 5)
            };
            var animalList = new List <IAnimal> {
                predator, carnivore1, carnivore2
            };

            _animalLogicMock
            .Setup(x => x.RemoveDeadAnimals(animalList))
            .Returns(() => animalList);

            _coordinatesLogicMock
            .Setup(x => x.GetPath(predator.Coordinates))
            .Returns(() => predator.Coordinates);

            // Act
            var result = _movementLogic.Behave(predator, animalList);

            // Assert
            Assert.False(result.Exists(x => !x.IsPredator && x.Symbol == ConstantValues.Dead));
        }
Esempio n. 4
0
        public void Zoo_WhenAddMamalAnimalIsOk_Increase_AnimalsNumberBy1()
        {
            // Arrange
            Antelope antelope    = new Antelope(name: "ant", age: 4, health: 100, Guid.NewGuid());
            int      startNumber = Zoo.GetNumberOfAnimals();

            // Act
            Zoo.AddAnimal(antelope);
            int newNumber = Zoo.GetNumberOfAnimals();

            // Assert
            Assert.Equal(startNumber + 1, newNumber);
        }
Esempio n. 5
0
        public void AnimalHealthCheck_AnimalWithoutHealth_AnimalDies()
        {
            Antelope antelope = new Antelope(2, 2)
            {
                Health = 0
            };

            _sut.AddHerbivores(antelope);

            Assert.Single(_sut.GetListOfHerbivores());
            _sut.Iteration(_playground);
            Assert.Empty(_sut.GetListOfHerbivores());
        }
Esempio n. 6
0
        public Animal CreateAnimal(ConsoleKey key, Field field)
        {
            var coordX = _facade.GetRandomMinMax(0, field.Width);
            var coordY = _facade.GetRandomMinMax(0, field.Height);

            if (_validator.AnimalExists(coordX, coordY, field))
            {
                CreateAnimal(key, field);
            }

            var newAnimal = new Animal();

            if (key == TextParameters.AntelopeKey)
            {
                newAnimal = new Antelope()
                {
                    Alive       = true,
                    CoordinateX = coordX,
                    CoordinateY = coordY,
                    Herbivore   = true,
                    Symbol      = TextParameters.Antelope,
                    Key         = TextParameters.AntelopeKey,
                    MatingCount = 0,
                    Health      = NumParameters.MaxHealth,
                };
            }
            else if (key == TextParameters.LionKey)
            {
                newAnimal = new Lion()
                {
                    Alive       = true,
                    CoordinateX = coordX,
                    CoordinateY = coordY,
                    Herbivore   = false,
                    Symbol      = TextParameters.Lion,
                    Key         = TextParameters.LionKey,
                    MatingCount = 0,
                    Health      = NumParameters.MaxHealth,
                };
            }

            field.Animals.Add(newAnimal);
            return(newAnimal);
        }
Esempio n. 7
0
        public void Zoo_WhenTryToRemoveAnimalFromEmptyZoo_Return_Exception()
        {
            // Arrange
            Antelope antelope    = new Antelope(name: "ant", age: 4, health: 100, Guid.NewGuid());
            bool     isException = false;

            // Act
            try
            {
                Zoo.RemoveAnimal(antelope);
            }
            catch
            {
                isException = true;
            }

            // Assert
            Assert.True(isException);
        }
        public void LocateEnemies_forLionAndAntelope_worksAsExpected()
        {
            var field    = new Field();
            var lion     = new Lion();
            var antelope = new Antelope();

            field.Animals.Add(lion);
            field.Animals.Add(antelope);
            var smallDistance = 1.0;
            var calculations  = new Mock <ICalculations>();

            calculations.Setup(c => c.Distance(It.IsAny <Animal>(), It.IsAny <Animal>())).Returns(smallDistance);
            var sut = new AnimalManager(calculations.Object);

            sut.LocateEnemies(field);

            lion.ClosestEnemy.Should().Be(antelope);
            antelope.ClosestEnemy.Should().Be(lion);
        }
Esempio n. 9
0
        public void SetNewPlayground_AddAnimal_AnimalAppearsOnPlayground()
        {
            Antelope antelope1 = new Antelope(2, 2)
            {
                XPaygroundCoordinate = 0, YPaygroundCoordinate = 0
            };
            Lion lion = new Lion(2, 2)
            {
                XPaygroundCoordinate = 1, YPaygroundCoordinate = 1
            };

            _sut.AddHerbivores(antelope1);
            _sut.AddHunters(lion);
            _sut.UpdatePlayground(_playground);

            char[,] arrays = _playground.GetPlaygroundArray();
            Assert.Equal('A', arrays[0, 0]);
            Assert.Equal('L', arrays[1, 1]);
        }
Esempio n. 10
0
        public void Behave_When_HealthEqualsOrLessThan0_Expect_SmallerAnimalList()
        {
            //Arrange
            var animal = new Antelope {
                Health = 0
            };
            var animalList = new List <IAnimal> {
                animal
            };

            _animalLogicMock
            .Setup(x => x.RemoveDeadAnimals(animalList))
            .Returns(() => animalList);

            // Act
            var result = _movementLogic.Behave(animal, animalList);

            // Assert
            Assert.IsEmpty(result);
        }
Esempio n. 11
0
        /// <summary>
        /// Demo : lion try to hunt antilope.
        /// </summary>
        static void LionHuntAntilope()
        {
            Console.WriteLine("\n*************** Lion hunt ***************\n");

            Lion lion = new Lion(name: "Simba", age: 4, health: 100, id: Guid.NewGuid())
            {
                Hunger = 80
            };
            Antelope antelope = new Antelope(name: "Lulu", age: 2, health: 30, id: Guid.NewGuid())
            {
                Hunger = 10
            };;

            // If lion is too hungry, he may try to hunt antilope.
            if (lion.IsHungry())
            {
                lion.Hunt(antelope);
            }

            lion.IsHungry();
        }
Esempio n. 12
0
        public void NumbersOfAnimals_AppearanceOfChild_CounterGoUp()
        {
            Antelope antelope1 = new Antelope(2, 2)
            {
                XPaygroundCoordinate = 2, YPaygroundCoordinate = 2
            };
            Antelope antelope2 = new Antelope(2, 2)
            {
                XPaygroundCoordinate = 1, YPaygroundCoordinate = 2
            };

            Assert.Equal(0, _sut.NumbersOfAnimals().Item1);

            _sut.AddHerbivores(antelope1);
            _sut.AddHerbivores(antelope2);
            Assert.Equal(2, _sut.NumbersOfAnimals().Item2);


            _sut.Iteration(_playground);
            _sut.Iteration(_playground);
            _sut.Iteration(_playground);
            Assert.Equal(3, _sut.NumbersOfAnimals().Item2);
        }