KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > distr > ProblemTest


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.distr;
11
12 import org.jgap.*;
13 import org.jgap.impl.*;
14
15 import junit.framework.*;
16
17 /**
18  * Tests the Problem class.
19  *
20  * @author Klaus Meffert
21  * @since 3.0
22  */

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

37   public void testConstruct_0() {
38     try {
39       new Problem(null, 3, null);
40       fail();
41     }
42     catch (IllegalArgumentException JavaDoc iex) {
43       ; //this is OK
44
}
45   }
46
47   /**
48    * @author Klaus Meffert
49    * @since 3.0
50    */

51   public void testConstruct_1() {
52     try {
53       new Problem(new StaticFitnessFunction(4.5d), 0, null);
54       fail();
55     }
56     catch (IllegalArgumentException JavaDoc iex) {
57       ; //this is OK
58
}
59   }
60
61   /**
62    * @author Klaus Meffert
63    * @since 3.0
64    */

65   public void testConstruct_2() {
66     try {
67       new Problem(new StaticFitnessFunction(4.5d), -1, null);
68       fail();
69     }
70     catch (IllegalArgumentException JavaDoc iex) {
71       ; //this is OK
72
}
73   }
74
75   /**
76    * @throws Exception
77    *
78    * @author Klaus Meffert
79    * @since 3.0
80    */

81   public void testConstruct_3() throws Exception JavaDoc {
82     FitnessFunction ff = new StaticFitnessFunction(4.5d);
83     Chromosome c = new Chromosome(conf);
84     Chromosome[] chroms = new Chromosome[]{c};
85     Problem p = new Problem(ff, 23, chroms);
86     assertEquals(23, p.getPopulationSize());
87     assertSame(ff, p.getFitnessFunction());
88     assertSame(chroms, p.getChromosomes());
89   }
90
91   /**
92    * @throws Exception
93    *
94    * @author Klaus Meffert
95    * @since 3.0
96    */

97   public void testGetID_0() throws Exception JavaDoc {
98     Problem p = new Problem();
99     String JavaDoc s = "2aXh-";
100     p.setID(s);
101     assertSame(s, p.getID());
102   }
103 }
104
Popular Tags