public void RenewPopulation_EngineNotStated_ThrowException() { var engine = new TestGeneticSearchEngineBuilder(2, 4, new TestPopulationManager(new double[] { 2, 2 })).Build(); engine.RenewPopulation(0.5); Assert.Fail("Should have thrown an exception by now"); }
public void RenewPopulation_BedPercentage_ThrowException(double percentage) { var engine = new TestGeneticSearchEngineBuilder(2, 4, new TestPopulationManager(new double[] { 2, 2 })).Build(); engine.Next(); engine.RenewPopulation(percentage); Assert.Fail("Should have thrown an exception by now"); }
public void RenewPopulation_EngineRunning_ThrowException() { using (var engine = new TestGeneticSearchEngineBuilder(2, int.MaxValue, new TestPopulationManager(new double[] { 2, 2 })).Build()) { Task.Run(() => engine.Run()); Thread.Sleep(50); // Give the eingine some time to start engine.RenewPopulation(0.5); Assert.Fail("Should have thrown an exception by now"); } }
public void RenewPercantagePopulation_PercentageRenewed(double percent) { var populationManager = new TestPopulationManager(new double[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }); populationManager.SetPopulationGenerated(new[] { new double[] { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } }); var engine = new TestGeneticSearchEngineBuilder(10, int.MaxValue, populationManager).Build(); engine.Next(); var result = engine.RenewPopulation(percent); var threeCounters = result.Population.Count(chromosme => chromosme.Evaluation == 3); Assert.AreEqual(percent * 10, threeCounters); }
public void RenewPopulation_CheckPopulationRenewedSentToNextGeneration() { var populationManager = new TestPopulationManager(new double[] { 2, 2 }, c => c.Evaluate() + 1); populationManager.SetPopulationGenerated(new[] { new double[] { 3, 3 } }); var engine = new TestGeneticSearchEngineBuilder(2, int.MaxValue, populationManager).Build(); engine.Next(); engine.RenewPopulation(1); var result = engine.Next(); foreach (var chromosme in result.Population) { Assert.AreEqual(4, chromosme.Evaluation); } }