public void TestCrossoverRecombinatorException() { Chromosome <BoolGene> chrom1 = new Chromosome <BoolGene>(1); Chromosome <BoolGene> chrom2 = new Chromosome <BoolGene>(2); IRecombinationProvider recom = new CrossoverRecombinator(); Chromosome <BoolGene> newChrom = chrom1.Recombine(chrom2, recom); }
public void TestCrossoverRecombinator() { Chromosome <BoolGene> father = new Chromosome <BoolGene>(2); Chromosome <BoolGene> mother = new Chromosome <BoolGene>(2); IRecombinationProvider recombinator = new CrossoverRecombinator(); father[0] = true; father[1] = false; mother[0] = false; mother[1] = true; Chromosome <BoolGene> child = father.Recombine(mother, recombinator); Assert.IsTrue(child[0] == true && child[1] == true, "Fix recombination not correct!"); // Following only functional with inverting Mutation! father[0].Mutate(); Assert.IsFalse(father[0]); father[0].Mutate(); Assert.IsTrue(father[0]); mother[1].Mutate(); child = father.Recombine(mother, recombinator); Assert.IsTrue(child[0].Equals(father[0]) && child[1].Equals(mother[1]), "Variable recombination not correct!"); }