1 10 package org.jgap.impl; 11 12 import java.util.*; 13 import org.jgap.*; 14 import junit.framework.*; 15 16 22 public class JGAPFactoryTest 23 extends JGAPTestCase { 24 25 private final static String CVS_REVISION = "$Revision: 1.4 $"; 26 27 public static Test suite() { 28 TestSuite suite = new TestSuite(JGAPFactoryTest.class); 29 return suite; 30 } 31 32 36 public void testConstruct_0() { 37 JGAPFactory factory = new JGAPFactory(false); 38 assertFalse(factory.isUseCaching()); 39 } 40 41 45 public void testConstruct_1() { 46 JGAPFactory factory = new JGAPFactory(true); 47 assertTrue(factory.isUseCaching()); 48 } 49 50 54 public void testSetParameters_0() { 55 JGAPFactory factory = new JGAPFactory(false); 56 List params = new Vector(); 57 params.add("Param1"); 58 params.add("Param2"); 59 factory.setParameters(params); 60 assertEquals(params, factory.getParameters()); 61 } 62 63 67 public void testRegisterCloneHandler_0() { 68 JGAPFactory factory = new JGAPFactory(false); 69 ICloneHandler cloneHandler = new DefaultCloneHandler(); 70 int index = factory.registerCloneHandler(cloneHandler); 71 assertEquals(0, index); 72 assertSame(cloneHandler, factory.removeCloneHandler(index)); 73 try { 74 assertNull(factory.removeCloneHandler(0)); 75 fail(); 76 } catch (IndexOutOfBoundsException iex) { 77 ; } 79 } 80 81 85 public void testRegisterCompareToHandler_0() { 86 JGAPFactory factory = new JGAPFactory(false); 87 ICompareToHandler cHandler = new DefaultCompareToHandler(); 88 int index = factory.registerCompareToHandler(cHandler); 89 assertEquals(0, index); 90 assertSame(cHandler, factory.removeCompareToHandler(index)); 91 try { 92 assertNull(factory.removeCompareToHandler(0)); 93 fail(); 94 } catch (IndexOutOfBoundsException iex) { 95 ; } 97 } 98 99 103 public void testRegisterInitializer_0() { 104 JGAPFactory factory = new JGAPFactory(false); 105 IInitializer initer = new DefaultInitializer(); 106 int index = factory.registerInitializer(initer); 107 assertEquals(0, index); 108 assertSame(initer, factory.removeInitializer(index)); 109 try { 110 assertNull(factory.removeInitializer(0)); 111 fail(); 112 } catch (IndexOutOfBoundsException iex) { 113 ; } 115 } 116 117 121 public void testCreateRandomGenerator_0() { 122 JGAPFactory factory = new JGAPFactory(true); 123 assertEquals(StockRandomGenerator.class, 124 factory.createRandomGenerator().getClass()); 125 } 126 127 133 public void testGetCloneHandlerFor_0() { 134 JGAPFactory factory = new JGAPFactory(false); 135 ICloneHandler cloneHandler = new DefaultCloneHandler(); 136 factory.registerCloneHandler(cloneHandler); 137 assertSame(cloneHandler, factory.getCloneHandlerFor(null, IApplicationData.class)); 138 } 139 140 146 public void testGetCloneHandlerFor_1() { 147 JGAPFactory factory = new JGAPFactory(true); 148 ICloneHandler cloneHandler = new DefaultCloneHandler(); 149 factory.registerCloneHandler(cloneHandler); 150 assertSame(cloneHandler, factory.getCloneHandlerFor(null, IApplicationData.class)); 151 assertSame(cloneHandler, factory.getCloneHandlerFor(null, IApplicationData.class)); 154 } 155 156 162 public void testGetCloneHandlerFor_2() { 163 JGAPFactory factory = new JGAPFactory(true); 164 ICloneHandler cloneHandler = new DefaultCloneHandler(); 165 factory.registerCloneHandler(cloneHandler); 166 assertNull(factory.getCloneHandlerFor(null, IntegerGene.class)); 167 assertNull(factory.getCloneHandlerFor(null, IntegerGene.class)); 168 } 169 170 176 public void testGetCloneHandlerFor_3() { 177 JGAPFactory factory = new JGAPFactory(false); 178 ICloneHandler cloneHandler = new DefaultCloneHandler(); 179 factory.registerCloneHandler(cloneHandler); 180 assertNull(factory.getCloneHandlerFor(null, IntegerGene.class)); 181 assertNull(factory.getCloneHandlerFor(null, IntegerGene.class)); 182 } 183 184 190 public void testGetCloneHandlerFor_4() { 191 JGAPFactory factory = new JGAPFactory(false); 192 ICloneHandler cloneHandler = new DefaultCloneHandler(); 193 factory.registerCloneHandler(cloneHandler); 194 assertNull(factory.getCloneHandlerFor(null, null)); 195 } 196 197 203 public void testGetCloneHandlerFor_5() { 204 JGAPFactory factory = new JGAPFactory(true); 205 ICloneHandler cloneHandler = new DefaultCloneHandler(); 206 factory.registerCloneHandler(cloneHandler); 207 assertNull(factory.getCloneHandlerFor(null, null)); 208 } 209 210 218 public void testGetCloneHandlerFor_6() 219 throws Exception { 220 JGAPFactory factory = new JGAPFactory(false); 221 ICloneHandler cloneHandler = new DefaultCloneHandler(); 222 factory.registerCloneHandler(cloneHandler); 223 Object inst = new IntegerGene(conf); 224 assertNull(factory.getCloneHandlerFor(inst, null)); 225 } 226 227 235 public void testGetCloneHandlerFor_7() 236 throws Exception { 237 JGAPFactory factory = new JGAPFactory(false); 238 ICloneHandler cloneHandler = new DefaultCloneHandler(); 239 factory.registerCloneHandler(cloneHandler); 240 Object inst = new Chromosome(conf); 241 assertSame(cloneHandler, factory.getCloneHandlerFor(inst, null)); 242 } 243 244 252 public void testIsSerializable_0() 253 throws Exception { 254 JGAPFactory inst = new JGAPFactory(false); 255 assertTrue(isSerializable(inst)); 256 } 257 258 267 public void testDoSerialize_0() 268 throws Exception { 269 JGAPFactory inst = new JGAPFactory(false); 270 Object o = doSerialize(inst); 271 assertEquals(o, inst); 272 } 273 274 } 275 | Popular Tags |