public void WagonFactory_RandomFishAnimals()
        {
            int animalAmount = 40;

            var animals = AnimalFactory.GenerateAnimals(typeof(Fish).Name, AnimalNames.Amphibians, animalAmount, 50);

            var wagons = WagonFactory.GenerateFilledWagons(animals);

            //check if all animals are added
            Assert.IsTrue(wagons.Sum(x => x.AllAnimals.Count) == animalAmount);

            foreach (var wagon in wagons)
            {
                var carnivore = wagon.AllAnimals.Where(x => x.AnimalDiet == AnimalDiet.Carnivores).ToList();
                var herbivore = wagon.AllAnimals.Where(x => x.AnimalDiet == AnimalDiet.Herbivores).ToList();

                if (carnivore != null && carnivore.Count > 0)
                {
                    Assert.IsTrue(carnivore.Count == 1);

                    for (int i = 0; i < carnivore.Count; i++)
                    {
                        var herbivoresIsSmaller = herbivore.Any(x => x.Weight < carnivore[i].Weight);

                        // if there is a carnivore in the wagon there can't be a smaller herbivore
                        Assert.IsTrue(herbivoresIsSmaller == false);
                    }
                }
            }
        }
示例#2
0
        private void BuildWagonTree()
        {
            if (totalAnimals == null || totalAnimals.Count == 0)
            {
                MessageBox.Show("there are no animals to fill the wagons with!");
                return;
            }

            totalWagons = WagonFactory.GenerateFilledWagons(totalAnimals);

            treeView2.Nodes.Clear();

            treeView2.BeginUpdate();

            for (int i = 0; i < totalWagons.Count; i++)
            {
                treeView2.Nodes.Add(totalWagons[i].Name);
                for (int j = 0; j < totalWagons[i].AllAnimals.Count; j++)
                {
                    Animal animal = totalWagons[i].AllAnimals[j];
                    treeView2.Nodes[i].Nodes.Add(animal.Name);

                    treeView2.Nodes[i].Nodes[j].Nodes.Add("Weight: " + animal.Weight.ToString() + " KG");
                    treeView2.Nodes[i].Nodes[j].Nodes.Add("Type: " + animal.AnimalDiet.ToString());
                    treeView2.Nodes[i].Nodes[j].Nodes.Add("WeightScore: " + animal.WeightScore().ToString() + " Points");
                }
            }
            treeView2.EndUpdate();
        }
示例#3
0
        public void CattleWagon_FillToMaxWeightScore()
        {
            //Assign
            List <Animal> animals = new List <Animal>();

            //Act
            for (int i = 0; i < 10; i++)
            {
                Animal animal = new Animal("testAnimal", 5, AnimalDiet.Herbivores);
                animals.Add(animal);
            }
            var result = WagonFactory.GenerateFilledWagons(animals);

            //Assert
            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0].AllAnimals.Count == 10);
        }
        public void WagonFactory_3Ominvore()
        {
            //Assign
            List <Animal> animals     = new List <Animal>();
            Bird          bird_1      = new Bird("test", 10f, AnimalDiet.Ominvores);
            Bird          bird_2      = new Bird("test", 10f, AnimalDiet.Ominvores);
            Amphibian     Amphibian_1 = new Amphibian("test", 10f, AnimalDiet.Ominvores);

            //Act

            animals.Add(bird_1);
            animals.Add(bird_1);
            animals.Add(Amphibian_1);

            var wagons = WagonFactory.GenerateFilledWagons(animals);

            //Assert
            Assert.IsTrue(wagons.Count == 1);
        }
        public void WagonFactory_2Ominvore1Carnivore()
        {
            //Assign
            List <Animal> animals     = new List <Animal>();
            Bird          bird_1      = new Bird("bird_1", 2f, AnimalDiet.Ominvores);
            Bird          bird_2      = new Bird("bird_2", 3f, AnimalDiet.Ominvores);
            Amphibian     Amphibian_1 = new Amphibian("Amphibian_1", 2.5f, AnimalDiet.Carnivores);

            //Act

            animals.Add(bird_1);
            animals.Add(bird_1);
            animals.Add(Amphibian_1);

            var wagons = WagonFactory.GenerateFilledWagons(animals);

            //Assert
            Assert.IsTrue(wagons.Count == 2);

            foreach (var wagon in wagons)
            {
                var carnivore = wagon.AllAnimals.Where(x => x.AnimalDiet == AnimalDiet.Carnivores).ToList();
                var ominvore  = wagon.AllAnimals.Where(x => x.AnimalDiet == AnimalDiet.Ominvores).ToList();

                if (carnivore != null && carnivore.Count > 0)
                {
                    Assert.IsTrue(carnivore.Count == 1);

                    for (int i = 0; i < carnivore.Count; i++)
                    {
                        var ominvoresIsSmaller = ominvore.Any(x => x.Weight < carnivore[i].Weight);

                        // if there is a carnivore in the wagon there can't be a smaller ominvore
                        Assert.IsTrue(ominvoresIsSmaller == false);
                    }
                }
            }
        }