KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > impl > FittestPopulationMergerTest


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.impl;
11
12 import org.jgap.*;
13 import org.jgap.distr.*;
14 import junit.framework.*;
15
16 /**
17  * Tests the FittestPopulationMerger class.
18  *
19  * @author Klaus Meffert
20  * @since 2.0
21  */

22 public class FittestPopulationMergerTest
23     extends JGAPTestCase {
24   /** String containing the CVS revision. Read out via reflection!*/
25   private final static String JavaDoc CVS_REVISION = "$Revision: 1.9 $";
26
27   public static Test suite() {
28     TestSuite suite = new TestSuite(FittestPopulationMergerTest.class);
29     return suite;
30   }
31
32   /**
33    * Test if construction possible
34    *
35    * @author Klaus Meffert
36    * @since 2.1
37    */

38   public void testConstruct_0() {
39     new FittestPopulationMerger();
40   }
41
42   /**
43    * @throws Exception
44    *
45    * @author Klaus Meffert
46    * @since 2.1
47    */

48   public void testMergePopulations_0()
49       throws Exception JavaDoc {
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