public void CattleWagon_FillToMaxWeight() { //Assign CattleWagon cattleWagon = new CattleWagon("testCattleWagon", 0, 100); Animal animal = new Animal("testAnimal", 100, AnimalDiet.Ominvores); bool added = false; //Act added = cattleWagon.AddAnimal(animal); //Assert Assert.IsTrue(added); }
public void CattleWagon_OverFillMaxWeight() { //Assign CattleWagon cattleWagon = new CattleWagon("testCattleWagon", 0, 100); Animal animal1 = new Animal("testAnimal1", 100, AnimalDiet.Ominvores); Animal animal2 = new Animal("testAnimal2", 100, AnimalDiet.Ominvores); bool added = false; //Act added = cattleWagon.AddAnimal(animal1); added = cattleWagon.AddAnimal(animal2); //Assert Assert.IsFalse(added); }
public void CattleWagon_BiggerHerbivoreAndCarnivores() { //Assign CattleWagon cattleWagon = new CattleWagon("testCattleWagon", 0, 1000); Animal animal1 = new Animal("testAnimal1", 100, AnimalDiet.Carnivores); Animal animal2 = new Animal("testAnimal1", 200, AnimalDiet.Herbivores); bool added = false; //Act added = cattleWagon.AddAnimal(animal1); added = cattleWagon.AddAnimal(animal2); //Assert Assert.IsTrue(added); }
public void CattleWagon_MoreThanOneCarnivores() { //Assign CattleWagon cattleWagon = new CattleWagon("testCattleWagon", 0, 1000); Animal animal1 = new Animal("testAnimal1", 100, AnimalDiet.Carnivores); Animal animal2 = new Animal("testAnimal1", 100, AnimalDiet.Carnivores); bool added = false; //Act added = cattleWagon.AddAnimal(animal1); added = cattleWagon.AddAnimal(animal2); //Assert Assert.IsFalse(added); }
public static List <CattleWagon> GenerateFilledWagons(List <Animal> animals) { var result = new List <CattleWagon>(); int count = 0; CattleWagon currentWagon = new CattleWagon($"wagon_{count}", 0, 1000); result.Add(currentWagon); //orders animal list by weight var animalsDesc = animals.OrderBy(s => s.Weight).ToList(); while (animalsDesc.Count != 0) { for (int i = 0; i < animalsDesc.Count; i++) { Animal animal = animalsDesc[i]; if (currentWagon.AddAnimal(animal)) { animalsDesc.Remove(animal); //reset the index i = -1; } } //if there are still animals add them to a new wagon if (animalsDesc.Count > 0) { count++; currentWagon = new CattleWagon($"wagon_{count}", 0, 1000); result.Add(currentWagon); } } return(result); }