public void EndCurrentGeneration_BestChromosomeChanged_ChangeEventRaise() { var target = new TplPopulation(2, 2, new ChromosomeStub()); var eventRaise = false; target.BestChromosomeChanged += (e, a) => { eventRaise = true; }; target.CreateInitialGeneration(); target.CurrentGeneration.Chromosomes.Each(c => c.Fitness = 1); target.EndCurrentGeneration(); Assert.IsTrue(eventRaise); }
public void CreateInitialGeneration_AdamChromosomeCreateNewNull_Exception() { var c = Substitute.For <ChromosomeBase>(4); c.CreateNew().Returns((IChromosome)null); var population = new TplPopulation(2, 2, c); Assert.Catch <InvalidOperationException>(() => { try { population.CreateInitialGeneration(); } catch (AggregateException e) { throw e.InnerException; } }, "The Adam chromosome's 'CreateNew' method generated a null chromosome. This is a invalid behavior, please, check your chromosome code."); }