Я делаю модульные тесты для проверки написанного мной алгоритма, к сожалению, эти тесты даже не запускаются из-за этой ошибки:
[10-6-2018 00:12:00Информационный] ========== Выполнить тест завершен: 0 прогон (0: 00: 06,5685302) ========== [10-6-2018 00:12:04 Информационный]------ Запуск теста начался ------ [10-6-2018 00:12:09 Ошибка] Активный запуск теста был прерван.Причина: Процесс прекращен из-за StackOverflowException.
Это все модульные тесты, которые у меня есть:
namespace AlgoritmeTest
{
[TestClass]
public class AlgoritmeTests
{
[TestMethod]
public void TestAddingWagonToTrain()
{
Train train = new Train();
Wagon wagon = new Wagon(10);
List<Wagon> expected = new List<Wagon>();
expected.Add(wagon);
train.AddWagon(wagon);
List<Wagon> actual = train.GetWagons();
Assert.AreEqual(expected, actual, "Failed to add wagon to train");
}
[TestMethod]
public void TestAddingAnimalToWagon()
{
Train train = new Train();
Wagon wagon = new Wagon(10);
Animal animal = new Animal("Goudvis", AnimalFood.Meat, AnimalSize.Big);
List<Animal> expected = new List<Animal>();
expected.Add(animal);
wagon.AddAnimal(animal);
List<Animal> actual = wagon.GetAnimals();
Assert.AreEqual(expected, actual, "Failed to add animal to wagon");
}
[TestMethod]
public void TestIfAnimalsAreReturned()
{
Animal animal = new Animal();
Animal goudvis = new Animal("Goudvis", AnimalFood.Meat, AnimalSize.Big);
Animal visstick = new Animal("Visstick", AnimalFood.Meat, AnimalSize.Big);
animal.animalsFromTheCircus.Add(goudvis);
animal.animalsFromTheCircus.Add(new Animal("Potvis", AnimalFood.Plants, AnimalSize.Medium));
animal.animalsFromTheCircus.Add(new Animal("Zalm", AnimalFood.Meat, AnimalSize.Small));
animal.animalsFromTheCircus.Add(visstick);
animal.animalsFromTheCircus.Add(new Animal("Varkenshaasje", AnimalFood.Plants, AnimalSize.Big));
List<Animal> expected = new List<Animal>();
expected.Add(goudvis);
expected.Add(visstick);
List<Animal> actual = animal.GetAllBigMeatEaters();
Assert.AreEqual(expected, actual, "Failed to get all animals which meet criteria");
}
[TestMethod]
public void TestIfAlgorithmStepWorks()
{
Program program = new Program();
Animal animal = new Animal();
Wagon wagon = new Wagon(10);
Wagon wagon2 = new Wagon(10);
Animal goudvis = new Animal("Goudvis", AnimalFood.Meat, AnimalSize.Big);
Animal visstick = new Animal("Visstick", AnimalFood.Meat, AnimalSize.Big);
animal.animalsFromTheCircus.Add(goudvis);
animal.animalsFromTheCircus.Add(visstick);
animal.animalsFromTheCircus.Add(new Animal("Potvis", AnimalFood.Plants, AnimalSize.Medium));
animal.animalsFromTheCircus.Add(new Animal("Zalm", AnimalFood.Meat, AnimalSize.Small));
animal.animalsFromTheCircus.Add(new Animal("Varkenshaasje", AnimalFood.Plants, AnimalSize.Big));
wagon.AddAnimal(goudvis);
wagon2.AddAnimal(visstick);
Train expected = new Train();
expected.AddWagon(wagon);
expected.AddWagon(wagon2);
program.SetUpProgram(animal.animalsFromTheCircus);
Train actual = program.AddAllMeatEaters();
Assert.AreEqual(expected, actual, "Failed to get all animals which meet criteria and place them in train according to alogrithm");
}
}
}
Animal.cs
public class Animal
{
private string animalName;
private AnimalFood animalFood;
private AnimalSize animalSize;
public Animal(string animalName, AnimalFood animalFood, AnimalSize animalSize)
{
this.animalName = animalName;
this.animalFood = animalFood;
this.animalSize = animalSize;
}
public Animal()
{
}
public List<Animal> animalsFromTheCircus = new DataGenerator().GenerateAnimals(100);
public List<Animal> GetallAnimals()
{
return animalsFromTheCircus;
}
public List<Animal> GetAllBigMeatEaters()
{
return animalsFromTheCircus.Where(animal => animal.getAnimalSize() == AnimalSize.Big && animal.getAnimalFood() == AnimalFood.Meat).ToList();
}
public List<Animal> GetAllBigMeatEaters(List<Animal> animalsFromTheCircus)
{
return animalsFromTheCircus.Where(animal => animal.getAnimalSize() == AnimalSize.Big && animal.getAnimalFood() == AnimalFood.Meat).ToList();
}
public List<Animal> GetAllSmallMeatEaters()
{
return animalsFromTheCircus.Where(animal => animal.getAnimalSize() == AnimalSize.Small && animal.getAnimalFood() == AnimalFood.Meat).ToList();
}
public List<Animal> GetAllBigPlantEaters()
{
return animalsFromTheCircus.Where(animal => animal.getAnimalSize() == AnimalSize.Big && animal.getAnimalFood() == AnimalFood.Plants).ToList();
}
public List<Animal> GetAllMediumMeatEaters()
{
return animalsFromTheCircus.Where(animal => animal.getAnimalSize() == AnimalSize.Medium && animal.getAnimalFood() == AnimalFood.Meat).ToList();
}
public List<Animal> GetAllMediumPlantEaters()
{
return animalsFromTheCircus.Where(animal => animal.getAnimalSize() == AnimalSize.Medium && animal.getAnimalFood() == AnimalFood.Plants).ToList();
}
public List<Animal> GetAllSmallPlantEaters()
{
return animalsFromTheCircus.Where(animal => animal.getAnimalSize() == AnimalSize.Small && animal.getAnimalFood() == AnimalFood.Plants).ToList();
}
public string getAnimalName()
{
return this.animalName;
}
public AnimalFood getAnimalFood()
{
return this.animalFood;
}
public AnimalSize getAnimalSize()
{
return this.animalSize;
}
}
Wagon.cs
public class Wagon
{
private List<Animal> animals;
private int maxSize;
public Wagon(int maxSize)
{
this.animals = new List<Animal>();
this.maxSize = maxSize;
}
public void AddAnimal(Animal animal)
{
this.animals.Add(animal);
}
public List<Animal> GetAnimals()
{
return this.animals;
}
}
Train.cs
public class Train
{
private List<Wagon> wagons;
public Train()
{
this.wagons = new List<Wagon>();
}
public void AddWagon(Wagon wagon)
{
this.wagons.Add(wagon);
}
public List<Wagon> GetWagons()
{
return this.wagons;
}
}
Что-то не так с моими тестами, почему выиграл?они бегут?