public void ChromosomeGenesCanBeForcedForTestPurpose() { var chromosome = new StretchChromosome(5, 2, 4, 1); var positions = chromosome.GetGenes().Select(g => (int)g.Value).ToArray(); Assert.That(positions[0], Is.EqualTo(4)); Assert.That(positions[1], Is.EqualTo(1)); }
public void ChromosomeGenesArePositionsWithinTheDefinedGrid() { var chromosome = new StretchChromosome(5, 2); var positions = chromosome.GetGenes().Select(g => (int)g.Value).ToArray(); Assert.That(positions.Length, Is.EqualTo(2)); Assert.That(positions[0], Is.Not.EqualTo(positions[1])); Assert.That(positions[0], Is.InRange(0, 4)); Assert.That(positions[1], Is.InRange(0, 4)); }
public void RandomChromosomesEnsureThatWhenTryingEnoughNewChromosomeHasFullyDifferentGenes() { var chromosomeRef = new StretchChromosome(5, 2); var positionsRef = chromosomeRef.GetGenes().Select(g => (int)g.Value).ToArray(); for (;;) { var chromosome = chromosomeRef.CreateNew(); var positions = chromosome.GetGenes().Select(g => (int)g.Value).ToArray(); if (positions[0] != positionsRef[0] && positions[1] != positionsRef[1]) { break; } } }
public void RandomChromosomesEnsureThatWhenTryingEnoughWeCanAllKindOfGenes() { var kindOfGenes = Enumerable.Repeat(0, 2 * 5).ToArray(); for (;;) { var chromosome = new StretchChromosome(5, 2); var positions = chromosome.GetGenes().Select(g => (int)g.Value).ToArray(); kindOfGenes[positions[0]] = 1; kindOfGenes[5 + positions[1]] = 1; if (kindOfGenes.Sum() == 10) { break; } } }