public void WhenCrossoverIsPerformed_RandomCrossover_50pcChance_ShouldBeApprox50pcCrossoverBetweenParents() { ConfigurationProvider.Crossover.ChanceOfRandomGeneCrossover = .5d; Population <bool> population = new Population <bool> (); int genomeLength = 100000; population.Initialise(2, genomeLength); population [0].Code.For((item, i) => population [0] [i] = false); population [1].Code.For((item, i) => population [1] [i] = true); double acceptableMin = (double)genomeLength * ((double)4.5d / 10); double acceptableMax = (double)genomeLength * ((double)5.5d / 10); int crossoverCount = 0; Crossover crossover = CrossoverProvider.GetCrossover(Crossover.CrossoverType.Random); var child = crossover.PerformCrossover(population [0], population [1]); child.Code.ForEach(b => crossoverCount += b ? 1 : 0); Assert.LessOrEqual(crossoverCount, acceptableMax); Assert.GreaterOrEqual(crossoverCount, acceptableMin); }