KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

35   public void testConstruct_0() {
36     try {
37       new Culture(0);
38       fail();
39     }
40     catch (IllegalArgumentException JavaDoc iex) {
41       ; //this is OK
42
}
43   }
44
45   /**
46    * @author Klaus Meffert
47    * @since 2.3
48    */

49   public void testConstruct_1() {
50     try {
51       new Culture( -3);
52       fail();
53     }
54     catch (IllegalArgumentException JavaDoc iex) {
55       ; //this is OK
56
}
57   }
58
59   /**
60    * @author Klaus Meffert
61    * @since 2.3
62    */

63   public void testConstruct_2() {
64     Culture c = new Culture(7);
65     assertEquals(7, c.size());
66   }
67
68   /**
69    * Illegal index.
70    *
71    * @author Klaus Meffert
72    * @since 2.3
73    */

74   public void testGet_0() {
75     try {
76       Culture c = new Culture(35);
77       c.set( -1, 2, 5, "");
78       fail();
79     }
80     catch (IllegalArgumentException JavaDoc iex) {
81       ; //this is OK
82
}
83   }
84
85   /**
86    * Illegal index (too high).
87    *
88    * @author Klaus Meffert
89    * @since 2.3
90    */

91   public void testGet_1() {
92     try {
93       Culture c = new Culture(35);
94       c.set(35, 2, 5, "");
95       fail();
96     }
97     catch (IllegalArgumentException JavaDoc iex) {
98       ; //this is OK
99
}
100   }
101
102   /**
103    * @author Klaus Meffert
104    * @since 2.3
105    */

106   public void testGet_2() {
107     Culture c = new Culture(9);
108     CultureMemoryCell cell1 = c.set(3, 5.7d, 0, "");
109     CultureMemoryCell cell = c.get(3);
110     assertSame(cell1, cell);
111     assertEquals(5.7d, cell.getCurrentValueAsDouble(), DELTA);
112     assertEquals(0, cell.getHistorySize());
113     assertEquals("", cell.getName());
114   }
115
116   /**
117    * @author Klaus Meffert
118    * @since 2.3
119    */

120   public void testGet_3() {
121     Culture c = new Culture(9);
122     CultureMemoryCell cell1 = c.set(3, -5.7d, -1, null);
123     CultureMemoryCell cell = c.get(3);
124     assertSame(cell1, cell);
125     assertEquals( -5.7d, cell.getCurrentValueAsDouble(), DELTA);
126     assertEquals(0, cell.getHistorySize());
127     assertEquals(null, cell.getName());
128   }
129
130   /**
131    * @author Klaus Meffert
132    * @since 2.3
133    */

134   public void testGet_4() {
135     Culture c = new Culture(11);
136     CultureMemoryCell cell1 = c.set(0, 0.0d, 17, "aName");
137     CultureMemoryCell cell = c.get(0);
138     assertSame(cell1, cell);
139     assertEquals(0.0d, cell.getCurrentValueAsDouble(), DELTA);
140     assertEquals(17, cell.getHistorySize());
141     assertEquals("aName", cell.getName());
142   }
143
144   /**
145    * @author Klaus Meffert
146    * @since 2.3
147    */

148   public void testGet_5() {
149     Culture c = new Culture(11);
150     CultureMemoryCell cell = c.get(7);
151     assertEquals(null, cell);
152   }
153
154   /**
155    * @author Klaus Meffert
156    * @since 2.3
157    */

158   public void testToString_0() {
159     Culture c = new Culture(11);
160     String JavaDoc s = "[";
161     for (int i = 0; i < c.size(); i++) {
162       if (i > 0) {
163         s += ";";
164       }
165       if (c.get(i) == null) {
166         s += "null";
167       }
168       else {
169         s += c.get(i).toString();
170       }
171     }
172     s += "]";
173     assertEquals(s, c.toString());
174   }
175
176   /**
177    * @author Klaus Meffert
178    * @since 2.3
179    */

180   public void testToString_1() {
181     Culture c = new Culture(11);
182     c.set(1, 0.0d, 17, "aName");
183     c.set(3, 23.5d, 5, "ANAME");
184     c.set(4, 19.6d, 0, "aName");
185     String JavaDoc s = "[";
186     for (int i = 0; i < c.size(); i++) {
187       if (i > 0) {
188         s += ";";
189       }
190       if (c.get(i) == null) {
191         s += "null";
192       }
193       else {
194         s += c.get(i).toString();
195       }
196     }
197     s += "]";
198     assertEquals(s, c.toString());
199   }
200
201   /**
202    * @throws Exception
203    *
204    * @author Klaus Meffert
205    * @since 2.3
206    */

207   public void testSerialize_0()
208       throws Exception JavaDoc {
209     Culture c = new Culture(11);
210     c.set(0, 2.3d, -1, "no name");
211     Culture c2 = (Culture) doSerialize(c);
212     assertEquals(c, c2);
213   }
214
215   /**
216    * @author Klaus Meffert
217    * @since 3.0
218    */

219   public void testClear_0() {
220     Culture c = new Culture(11);
221     c.set(1, 2.3d, -1, "no name");
222     c.set("hallo", new Double JavaDoc(2.3d), -1);
223     c.clear();
224     // Check named memory.
225
assertEquals(0, c.getMemoryNames().size());
226     // Check memory cells themselves.
227
for (int i = 0; i < c.size(); i++) {
228       assertNull(c.get(i));
229     }
230   }
231
232   /**
233    * @author Klaus Meffert
234    * @since 3.2
235    */

236   public void testContains_0() {
237     Culture c = new Culture(11);
238     c.set("uniquename","value",-1);
239     assertTrue(c.contains("uniquename"));
240     assertFalse(c.contains("uniqueName"));
241     assertFalse(c.contains("UNIQUENAME"));
242     assertTrue(c.contains("uniquename"));
243     c.clear();
244     assertFalse(c.contains("uniquename"));
245   }
246
247   /**
248    * @author Klaus Meffert
249    * @since 3.2
250    */

251   public void testContains_1() {
252     Culture c = new Culture(7);
253     assertFalse(c.contains("uniquename"));
254     assertFalse(c.contains("*"));
255     assertFalse(c.contains("%"));
256   }
257
258   /**
259    * @author Klaus Meffert
260    * @since 3.2
261    */

262   public void testContains_2() {
263     Culture c = new Culture(7);
264     try {
265       assertFalse(c.contains(""));
266       fail();
267     }catch (IllegalArgumentException JavaDoc iex) {
268       ; // this is OK
269
}
270   }
271
272   /**
273    * @author Klaus Meffert
274    * @since 3.2
275    */

276   public void testContains_3() {
277     Culture c = new Culture(7);
278     try {
279       assertFalse(c.contains(null));
280       fail();
281     }catch (IllegalArgumentException JavaDoc iex) {
282       ; // this is OK
283
}
284   }
285 }
286
Popular Tags