KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

44   public void testCalculateCurrentRate_0() throws Exception JavaDoc {
45     IUniversalRateCalculator calc = new DefaultMutationRateCalculator(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 3.0
58    */

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

76   public void testCalculateCurrentRate_2() throws Exception JavaDoc {
77     IUniversalRateCalculator calc = new DefaultMutationRateCalculator(conf);
78     int rate = calc.calculateCurrentRate();
79     assertEquals(1, rate);
80   }
81 }
82
Popular Tags