1 10 package org.jgap.gp.impl; 11 12 import java.util.*; 13 import junit.framework.*; 14 import org.jgap.*; 15 import org.jgap.gp.*; 16 17 23 public class GPConfigurationTest 24 extends GPTestCase { 25 26 private final static String CVS_REVISION = "$Revision: 1.5 $"; 27 28 public static Test suite() { 29 TestSuite suite = new TestSuite(GPConfigurationTest.class); 30 return suite; 31 } 32 33 public void setUp() { 34 super.setUp(); 35 } 36 37 43 public void testSerialize_0() 44 throws Exception { 45 GPConfiguration.reset(); 46 GPConfiguration conf = new GPConfiguration(); 47 GPConfiguration conf2 = (GPConfiguration) doSerialize(conf); 48 assertEquals(conf, conf2); 49 } 50 51 57 public void testMemory_0() 58 throws Exception { 59 GPConfiguration.reset(); 60 GPConfiguration conf = new GPConfiguration(); 61 conf.storeInMemory("name1", "test1"); 62 assertEquals("test1", conf.readFromMemory("name1")); 63 } 64 65 71 public void testMemory_1() 72 throws Exception { 73 GPConfiguration.reset(); 74 GPConfiguration conf = new GPConfiguration(); 75 try { 76 conf.readFromMemory("name1"); 77 fail(); 78 } catch (IllegalArgumentException iex) { 79 ; } 81 } 82 83 89 public void testMemory_2() 90 throws Exception { 91 GPConfiguration.reset(); 92 GPConfiguration conf = new GPConfiguration(); 93 conf.storeInMemory("name1", "test1"); 94 conf.storeInMemory("name2", "test2"); 95 conf.storeInMemory("name3", "test3"); 96 assertEquals("test2", conf.readFromMemory("name2")); 97 assertEquals("test2", conf.readFromMemory("name2")); 100 assertEquals("test1", conf.readFromMemory("name1")); 103 assertEquals("test3", conf.readFromMemory("name3")); 104 } 105 106 112 public void testMemory_3() 113 throws Exception { 114 GPConfiguration.reset(); 115 GPConfiguration conf = new GPConfiguration(); 116 conf.storeInMemory("name1", "test1"); 117 conf.clearMemory(); 118 try { 119 conf.readFromMemory("name1"); 120 fail(); 121 } catch (IllegalArgumentException iex) { 122 ; } 124 } 125 126 132 public void testStack_0() 133 throws Exception { 134 GPConfiguration.reset(); 135 GPConfiguration conf = new GPConfiguration(); 136 assertEquals(0, conf.stackSize()); 137 try { 138 assertNull(conf.peekStack()); 139 fail(); 140 } catch (EmptyStackException eex) { 141 ; } 143 } 144 145 151 public void testStack_1() 152 throws Exception { 153 GPConfiguration.reset(); 154 GPConfiguration conf = new GPConfiguration(); 155 conf.pushToStack("test1"); 156 assertEquals(1, conf.stackSize()); 157 conf.pushToStack("test2"); 158 assertEquals(2, conf.stackSize()); 159 assertEquals("test2", conf.popFromStack()); 160 assertEquals(1, conf.stackSize()); 161 assertEquals("test1", conf.popFromStack()); 162 assertEquals(0, conf.stackSize()); 163 } 164 165 171 public void testStack_2() 172 throws Exception { 173 GPConfiguration.reset(); 174 GPConfiguration conf = new GPConfiguration(); 175 Vector obj = new Vector(); 176 conf.pushToStack(obj); 177 assertSame(obj, conf.peekStack()); 178 assertSame(obj, conf.popFromStack()); 179 } 180 181 187 public void testStack_3() 188 throws Exception { 189 GPConfiguration.reset(); 190 GPConfiguration conf = new GPConfiguration(); 191 try { 192 conf.popFromStack(); 193 fail(); 194 } catch (EmptyStackException eex) { 195 ; } 197 } 198 199 205 public void testStack_4() 206 throws Exception { 207 GPConfiguration.reset(); 208 GPConfiguration conf = new GPConfiguration(); 209 conf.pushToStack("test1"); 210 conf.clearStack(); 211 assertEquals(0, conf.stackSize()); 212 } 213 214 220 public void testSetSelectionMethod_0() 221 throws Exception { 222 GPConfiguration.reset(); 223 GPConfiguration conf = new GPConfiguration(); 224 try { 225 conf.setSelectionMethod(null); 226 fail(); 227 } catch (IllegalArgumentException iex) { 228 ; } 230 } 231 232 238 public void testSetSelectionMethod_1() 239 throws Exception { 240 GPConfiguration.reset(); 241 GPConfiguration conf = new GPConfiguration(); 242 INaturalGPSelector sel = new FitnessProportionateSelection(); 243 conf.setSelectionMethod(sel); 244 assertSame(sel, conf.getSelectionMethod()); 245 } 246 247 253 public void testSetCrossoverMethod_0() 254 throws Exception { 255 GPConfiguration.reset(); 256 GPConfiguration conf = new GPConfiguration(); 257 try { 258 conf.setCrossoverMethod(null); 259 fail(); 260 } catch (IllegalArgumentException iex) { 261 ; } 263 } 264 265 271 public void testSetCrossoverMethod_1() 272 throws Exception { 273 GPConfiguration.reset(); 274 GPConfiguration conf = new GPConfiguration(); 275 CrossMethod cross = new BranchTypingCross(conf); 276 conf.setCrossoverMethod(cross); 277 assertSame(cross, conf.getCrossMethod()); 278 } 279 280 286 public void testConstructor_0() 287 throws Exception { 288 GPConfiguration.reset(); 289 GPConfiguration conf = new GPConfiguration(); 290 assertEquals(BranchTypingCross.class, conf.getCrossMethod().getClass()); 291 assertEquals(FitnessProportionateSelection.class, 292 conf.getSelectionMethod().getClass()); 293 assertEquals(DefaultGPFitnessEvaluator.class, 294 conf.getGPFitnessEvaluator().getClass()); 295 } 296 297 303 public void testConstructor_1() 304 throws Exception { 305 GPConfiguration.reset(); 306 FitnessProportionateSelection sel = new FitnessProportionateSelection(); 307 GPConfiguration conf = new GPConfiguration(sel); 308 assertSame(sel, conf.getSelectionMethod()); 309 } 310 } 311 | Popular Tags |