private void FillRemainders(List <Animal> remainders, CircusTrain train)
 {
     Enumerable.Range(0, remainders.Count)
     .ToList()
     .ForEach(i =>
     {
         train.TryAddToWagonWithRoom(remainders[0]);
         remainders.RemoveAt(0);
     });
 }
示例#2
0
        public void AddAnimal_Add2Animals_True()
        {
            // Arrange
            CircusTrain   train   = new CircusTrain();
            List <Animal> animals = new List <Animal>()
            {
                new Animal(Diet.Carnivore, Size.Large),
                new Animal(Diet.Carnivore, Size.Large),
            };

            // Act
            animals = animals.OrderBy(animal => animal.Diet).ThenByDescending(animal => animal.Size).ToList();
            animals.ForEach(animal => train.AddAnimal(animal));

            // Assert
            Assert.AreEqual(2, train.Wagons.Count);
        }
示例#3
0
        public void AddAnimal_Add3Animals_True()
        {
            // Arrange
            CircusTrain   train   = new CircusTrain();
            List <Animal> animals = new List <Animal>()
            {
                new Animal(Diet.Carnivore, Size.Large),
                new Animal(Diet.Herbivore, Size.Medium),
                new Animal(Diet.Carnivore, Size.Medium),
            };

            // Act
            animals = animals.OrderBy(animal => animal.Diet).ThenByDescending(animal => animal.Size).ToList();
            animals.ForEach(animal => train.AddAnimal(animal));
            IReadOnlyList <Animal> animalsInTrain = train.Animals;

            // Assert
            Assert.IsTrue(animalsInTrain[0].Size == Size.Large & animalsInTrain[0].Diet == Diet.Carnivore);
            Assert.IsTrue(animalsInTrain[1].Size == Size.Medium & animalsInTrain[1].Diet == Diet.Carnivore);
            Assert.IsTrue(animalsInTrain[2].Size == Size.Medium & animalsInTrain[2].Diet == Diet.Herbivore);
        }
        public void SortAnimals(List <Animal> animals, CircusTrain train)
        {
            var herbivores = GetHerbivores(animals);

            train.Wagons
            .Where(wagon => wagon.IsFull == false)
            .ToList()
            .ForEach(wagon =>
            {
                while (wagon.IsFull == false && herbivores.OrderByDescending(a => a.Size).Count(a => (int)a.Size > (int)wagon.GetMeatEaterSize()) != 0)
                {
                    var animal = herbivores.Where(a => (int)a.Size > (int)wagon.GetMeatEaterSize()).OrderBy(a => a.Size).FirstOrDefault();
                    if ((int)wagon.GetMeatEaterSize() < (int)animal.Size &&
                        wagon.Points + animal.Points <= Wagon.MaxPoints)
                    {
                        herbivores.Remove(animal);
                        wagon.AddAnimal(animal);
                    }
                    else
                    {
                        break;
                    }
                }

                if (wagon.GetMeatEaterSize() == AnimalSize.Small && wagon.Points <= Wagon.MaxPoints - ((int)AnimalSize.Medium - (int)AnimalSize.Small))
                {
                    var animal = herbivores.FirstOrDefault(a => a.Size == AnimalSize.Large && a.Eater == AnimalEater.Herbivore);
                    if (animal != null)
                    {
                        herbivores.Add(wagon.SwitchSmallToMediumAnimal(animal));
                        herbivores.Remove(animal);
                    }
                }
            });
            FillRemainders(herbivores, train);
        }
示例#5
0
        public void SortAnimals(List <Animal> animals, CircusTrain train)
        {
            var meateaters = GetMeatEaters(animals);

            meateaters.ForEach(train.AddToNewWagon);
        }
示例#6
0
 public CircusTrainFiller()
 {
     loader  = new AnimalSorterLoader();
     sorters = loader.ReturnSorters();
     train   = new CircusTrain();
 }