1 10 package org.jgap.impl; 11 12 import org.jgap.*; 13 import org.jgap.distr.*; 14 import junit.framework.*; 15 16 22 public class FittestPopulationMergerTest 23 extends JGAPTestCase { 24 25 private final static String CVS_REVISION = "$Revision: 1.9 $"; 26 27 public static Test suite() { 28 TestSuite suite = new TestSuite(FittestPopulationMergerTest.class); 29 return suite; 30 } 31 32 38 public void testConstruct_0() { 39 new FittestPopulationMerger(); 40 } 41 42 48 public void testMergePopulations_0() 49 throws Exception { 50 Gene gene = new BooleanGene(conf); 51 Chromosome chrom = new Chromosome(conf, gene, 4); 52 chrom.setFitnessValue(5); 53 Chromosome[] chroms1 = new Chromosome[3]; 54 chroms1[0] = chrom; 55 chrom = new Chromosome(conf, gene, 1); 56 chrom.setFitnessValue(7); 57 chroms1[1] = chrom; 58 chrom = new Chromosome(conf, gene, 1); 59 chrom.setFitnessValue(2); 60 chroms1[2] = chrom; 61 Chromosome[] chroms2 = new Chromosome[4]; 62 chrom = new Chromosome(conf, gene, 1); 63 chrom.setFitnessValue(4); 64 chroms2[0] = chrom; 65 chrom = new Chromosome(conf, gene, 1); 66 chrom.setFitnessValue(7); 67 chroms2[1] = chrom; 68 chrom = new Chromosome(conf, gene, 1); 69 chrom.setFitnessValue(1); 70 chroms2[2] = chrom; 71 chrom = new Chromosome(conf, gene, 1); 72 chrom.setFitnessValue(10); 73 chroms2[3] = chrom; 74 Population pop1 = new Population(conf, chroms1); 75 Population pop2 = new Population(conf, chroms2); 76 IPopulationMerger merger = new FittestPopulationMerger(); 77 Population result = merger.mergePopulations(pop1, pop2, 4); 78 assertEquals(4, result.size()); 79 assertEquals(10.0d, result.getChromosome(0).getFitnessValue(), DELTA); 80 assertEquals(7.0d, result.getChromosome(1).getFitnessValue(), DELTA); 81 assertEquals(7.0d, result.getChromosome(2).getFitnessValue(), DELTA); 82 assertEquals(5.0d, result.getChromosome(3).getFitnessValue(), DELTA); 83 } 84 } 85 | Popular Tags |