1 10 package org.jgap.gp; 11 12 import junit.framework.*; 13 import org.jgap.*; 14 import org.jgap.gp.impl.*; 15 16 22 public class CommandGeneTest 23 extends GPTestCase { 24 25 private final static String CVS_REVISION = "$Revision: 1.6 $"; 26 27 public static Test suite() { 28 TestSuite suite = new TestSuite(CommandGeneTest.class); 29 return suite; 30 } 31 32 39 public void testConstruct_0() 40 throws Exception { 41 assertNotNull(new CommandGeneImpl(m_gpconf)); 42 } 43 44 50 public void testToString_0() 51 throws Exception { 52 CommandGene gene = new CommandGeneImpl(m_gpconf); 53 assertEquals("test", gene.toString()); 54 } 55 56 62 public void testSetAllele_0() 63 throws Exception { 64 CommandGene gene = new CommandGeneImpl(m_gpconf); 65 try { 66 gene.setAllele(new Double (75)); 67 fail(); 68 }catch (UnsupportedOperationException uex) { 69 ; } 71 } 72 73 79 public void testSize_0() 80 throws Exception { 81 CommandGene gene = new CommandGeneImpl(m_gpconf); 82 assertEquals(1, gene.size()); 83 } 84 85 91 public void testEquals_0() 92 throws Exception { 93 CommandGeneImpl gene = new CommandGeneImpl(m_gpconf); 94 assertFalse(gene.equals(null)); 95 assertTrue(gene.equals(gene)); 96 assertFalse(gene.equals(new Integer (2))); 97 } 98 99 105 public void testEquals_1() 106 throws Exception { 107 CommandGeneImpl gene = new CommandGeneImpl(m_gpconf); 108 assertFalse(gene.equals(null)); 109 assertTrue(gene.equals(gene)); 110 assertFalse(gene.equals(new Integer (2))); 111 } 112 113 119 public void testEquals_2() 120 throws Exception { 121 CommandGeneImpl gene = new CommandGeneImpl(m_gpconf); 122 assertFalse(gene.equals(null)); 123 assertTrue(gene.equals(gene)); 124 assertFalse(gene.equals(new Integer (2))); 125 } 126 127 134 public void testEquals_3() 135 throws Exception { 136 Configuration conf = new ConfigurationForTest(); 137 CommandGeneImpl gene = new CommandGeneImpl(m_gpconf); 138 gene.setApplicationData(new AppDataForTest()); 139 CommandGeneImpl gene2 = new CommandGeneImpl(m_gpconf); 140 gene2.setApplicationData(new AppDataForTest()); 141 gene.setCompareApplicationData(true); 142 assertTrue(gene.equals(gene2)); 143 146 } 147 148 156 public void testCleanup_0() 157 throws Exception { 158 CommandGene gene = new CommandGeneImpl(m_gpconf); 159 gene.cleanup(); 160 } 161 162 168 public void testHashCode_0() 169 throws Exception { 170 CommandGeneImpl gene = new CommandGeneImpl(m_gpconf); 171 assertEquals( gene.getClass().getName().hashCode(), gene.hashCode()); 172 } 173 174 180 public void testHashCode_1() 181 throws Exception { 182 CommandGeneImpl gene = new CommandGeneImpl(m_gpconf); 183 } 187 188 194 public void testSetEnergy_0() 195 throws Exception { 196 CommandGeneImpl gene = new CommandGeneImpl(m_gpconf); 197 assertEquals(0.0, gene.getEnergy(), DELTA); 198 gene.setEnergy(2.3); 199 assertEquals(2.3, gene.getEnergy(), DELTA); 200 } 201 202 208 public void testSetEnergy_1() 209 throws Exception { 210 CommandGeneImpl gene = new CommandGeneImpl(m_gpconf); 211 gene.setEnergy(2.3); 212 assertEquals(2.3, gene.getEnergy(), DELTA); 213 gene.setEnergy( -55.8); 214 assertEquals( -55.8, gene.getEnergy(), DELTA); 215 gene.setEnergy(0.5); 216 gene.setEnergy(0.8); 217 assertEquals(0.8, gene.getEnergy(), DELTA); 218 } 219 220 226 public void testSetApplicationData_0() 227 throws Exception { 228 CommandGeneImpl gene = new CommandGeneImpl(m_gpconf); 229 assertNull(gene.getApplicationData()); 230 Integer i = new Integer (23); 231 gene.setApplicationData(i); 232 assertSame(i, gene.getApplicationData()); 233 String s = "Hallo"; 234 gene.setApplicationData(s); 235 assertSame(s, gene.getApplicationData()); 236 } 237 238 244 public void testIsCompareApplicationData_0() 245 throws Exception { 246 CommandGeneImpl gene = new CommandGeneImpl(m_gpconf); 247 assertFalse(gene.isCompareApplicationData()); 248 gene.setCompareApplicationData(false); 249 assertFalse(gene.isCompareApplicationData()); 250 gene.setCompareApplicationData(true); 251 assertTrue(gene.isCompareApplicationData()); 252 } 253 254 260 class CommandGeneImpl 261 extends CommandGene { 262 263 public CommandGeneImpl(final GPConfiguration a_config) 264 throws InvalidConfigurationException { 265 super(a_config,1,CommandGene.FloatClass); 266 } 267 268 protected Gene newGeneInternal() { 269 return null; 270 } 271 272 public Class getChildType(IGPProgram a_ind, int a_chromNum) { 273 return null; 274 } 275 276 public String toString() { 277 return "test"; 278 } 279 280 } 281 class AppDataForTest 282 implements IApplicationData { 283 public int compareTo(Object o2) { 284 return 0; 285 } 286 287 public Object clone() 288 throws CloneNotSupportedException { 289 return null; 290 } 291 } 292 } 293 | Popular Tags |