KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.*;
14
15 /**
16  * Tests the ChromosomePool class.
17  *
18  * @author Klaus Meffert
19  * @since 2.0
20  */

21 public class ChromosomePoolTest
22     extends JGAPTestCase {
23   /** String containing the CVS revision. Read out via reflection!*/
24   private final static String JavaDoc CVS_REVISION = "$Revision: 1.9 $";
25
26   public static Test suite() {
27     TestSuite suite = new TestSuite(ChromosomePoolTest.class);
28     return suite;
29   }
30
31   public void setUp() {
32     super.setUp();
33     Configuration.reset();
34   }
35
36   /**
37    * Test if construction possible without failure.
38    * @throws Exception
39    *
40    * @author Klaus Meffert
41    * @since 2.0
42    */

43   public void testConstruct_0() throws Exception JavaDoc {
44     ChromosomePool pool = new ChromosomePool();
45     Pool p = (Pool)privateAccessor.getField(pool, "m_chromosomePool");
46     assertNotNull(p);
47   }
48
49   /**
50    * @author Klaus Meffert
51    * @since 2.0
52    */

53   public void testAquireChromosome_0() {
54     assertEquals(null, new ChromosomePool().acquireChromosome());
55   }
56
57   /**
58    * @author Klaus Meffert
59    * @since 2.0
60    */

61   public void testReleaseChromosome_0() {
62     try {
63       new ChromosomePool().releaseChromosome(null);
64       fail();
65     }
66     catch (IllegalArgumentException JavaDoc nex) {
67       ; //this is OK
68
}
69   }
70
71   /**
72    * Should be possible without exception.
73    * @throws Exception
74    *
75    * @author Klaus Meffert
76    * @since 2.0
77    */

78   public void testReleaseChromosome_1()
79       throws Exception JavaDoc {
80     ChromosomePool pool = new ChromosomePool();
81     Configuration conf = new DefaultConfiguration();
82     conf.setFitnessFunction(new TestFitnessFunction());
83     conf.setPopulationSize(5);
84     Gene sampleGene = new IntegerGene(conf, 1, 10);
85     Chromosome chrom = new Chromosome(conf, sampleGene, 3);
86     conf.setSampleChromosome(chrom);
87     pool.releaseChromosome(chrom);
88   }
89 }
90
Popular Tags