public void ElitismStrategy_GetElitistGeneticEntities_NullPopulation() { MockElitismStrategy strategy = new MockElitismStrategy(); strategy.Initialize(GetGeneticAlgorithm(.1)); Assert.Throws <ArgumentNullException>(() => strategy.GetEliteEntities(null)); }
public async Task ElitismStrategy_GetElitistGeneticEntities() { double elitismRatio = .1; int totalGeneticEntities = 100; GeneticAlgorithm algorithm = GetGeneticAlgorithm(elitismRatio); await algorithm.InitializeAsync(); MockPopulation population = new MockPopulation(); population.Initialize(algorithm); for (int i = 0; i < totalGeneticEntities; i++) { MockEntity entity = new MockEntity(); entity.Initialize(algorithm); population.Entities.Add(entity); } algorithm.Environment.Populations.Add(population); MockElitismStrategy strategy = (MockElitismStrategy)algorithm.ElitismStrategy; strategy.Initialize(algorithm); IList <GeneticEntity> geneticEntities = strategy.GetEliteEntities(population); Assert.Equal(Convert.ToInt32(Math.Round(elitismRatio * totalGeneticEntities)), geneticEntities.Count); }
public void ElitismStrategy_GetElitistGeneticEntities_EmptyPopulation() { GeneticAlgorithm algorithm = GetGeneticAlgorithm(.1); MockElitismStrategy strategy = new MockElitismStrategy(); strategy.Initialize(algorithm); MockPopulation pop = new MockPopulation(); pop.Initialize(algorithm); Assert.Throws <ArgumentException>(() => strategy.GetEliteEntities(pop)); }