KickJava   Java API By Example, From Geeks To Geeks.

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


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 DefaultCrossoverRateCalculator class.
17  *
18  * @author Klaus Meffert
19  * @since 2.0
20  */

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

43   public void testCalculateCurrentRate_0()
44       throws Exception JavaDoc {
45     IUniversalRateCalculator calc = new DefaultCrossoverRateCalculator(conf);
46     Gene gene = new IntegerGene(conf, 1, 5);
47     Chromosome chrom = new Chromosome(conf, gene, 50);
48     conf.setSampleChromosome(chrom);
49     int rate = calc.calculateCurrentRate();
50     assertEquals(conf.getChromosomeSize(), rate);
51   }
52
53   /**
54    * @throws Exception
55    *
56    * @author Klaus Meffert
57    * @since 2.0
58    */

59   public void testCalculateCurrentRate_01()
60       throws Exception JavaDoc {
61     IUniversalRateCalculator calc = new DefaultCrossoverRateCalculator(conf);
62     Gene gene = new IntegerGene(conf, 1, 5);
63     Chromosome chrom = new Chromosome(conf, gene, 30);
64     conf.setSampleChromosome(chrom);
65     int rate = calc.calculateCurrentRate();
66     assertEquals(conf.getChromosomeSize(), rate);
67   }
68
69   /**
70    * If there are zero chromosomes in the config., the crossover rate
71    * nevertheless should be 1, because Random needs positive integers as input
72    * (see CrossoverOperator.operate for calling Random class)
73    * @throws Exception
74    *
75    * @author Klaus Meffert
76    * @since 2.0
77    */

78   public void testCalculateCurrentRate_1()
79       throws Exception JavaDoc {
80     IUniversalRateCalculator calc = new DefaultCrossoverRateCalculator(conf);
81     int rate = calc.calculateCurrentRate();
82     assertEquals(1, rate);
83   }
84
85   /**
86    * @throws Exception
87    *
88    * @author Klaus Meffert
89    * @since 2.2
90    */

91   public void testToBePermutated_0()
92       throws Exception JavaDoc {
93     IUniversalRateCalculator calc = new DefaultCrossoverRateCalculator(conf);
94     assertTrue(calc.toBePermutated(null, 0));
95   }
96 }
97
Popular Tags