1 10 package org.jgap.gp.impl; 11 12 import junit.framework.*; 13 import org.jgap.*; 14 import org.jgap.impl.*; 15 import org.jgap.gp.terminal.*; 16 import org.jgap.gp.function.*; 17 18 import org.jgap.gp.*; 19 20 26 public class GPPopulationTest 27 extends GPTestCase { 28 29 private final static String CVS_REVISION = "$Revision: 1.2 $"; 30 31 public static Test suite() { 32 TestSuite suite = new TestSuite(GPPopulationTest.class); 33 return suite; 34 } 35 36 public void setUp() { 37 super.setUp(); 38 } 39 40 46 public void testConstruct_0() 47 throws Exception { 48 GPPopulation gppop = new GPPopulation(m_gpconf, 10); 49 assertEquals(10, gppop.getPopSize()); 50 assertEquals(10, gppop.size()); 51 } 52 53 61 public void testCreate_0() 62 throws Exception { 63 GPPopulation gppop = new GPPopulation(m_gpconf, 10); 64 Class [] types = { 65 CommandGene.IntegerClass}; 66 Class [][] argTypes = { {} 67 }; 68 CommandGene[][] nodeSets = { { 69 } 70 }; 71 try { 72 gppop.create(types, argTypes, nodeSets, new int[] {1}, new int[] {1}, 1, 73 true, 10, new boolean[] {true}); 74 fail(); 75 } catch (IllegalStateException iex) { 76 ; } 78 } 79 80 86 public void testCreate_1() 87 throws Exception { 88 GPPopulation gppop = new GPPopulation(m_gpconf, 10); 89 Class [] types = { 90 CommandGene.IntegerClass}; 91 Class [][] argTypes = { {} 92 }; 93 CommandGene[][] nodeSets = { { 94 new Add(m_gpconf, CommandGene.IntegerClass), 95 Variable.create(m_gpconf, "X", CommandGene.IntegerClass), 96 new Constant(m_gpconf, CommandGene.IntegerClass, new Integer (1)), 97 } 98 }; 99 rn.setNextInt(2); 101 } 106 107 113 public void testCreate_2() 114 throws Exception { 115 GPPopulation gppop = new GPPopulation(m_gpconf, 10); 116 Class [] types = { 117 CommandGene.IntegerClass}; 118 Class [][] argTypes = { {} 119 }; 120 CommandGene[][] nodeSets = { { 121 new Add(m_gpconf, CommandGene.IntegerClass), 122 Variable.create(m_gpconf, "X", CommandGene.IntegerClass), 123 new Constant(m_gpconf, CommandGene.IntegerClass, new Integer (1)), 124 } 125 }; 126 rn.setNextIntSequence(new int[] {0, 2, 1}); 128 129 } 138 139 147 public void testCreate_3() 148 throws Exception { 149 GPPopulation gppop = new GPPopulation(m_gpconf, 10); 150 Class [] types = { 151 CommandGene.IntegerClass}; 152 Class [][] argTypes = { {} 153 }; 154 CommandGene[][] nodeSets = { { 155 new Add(m_gpconf, CommandGene.IntegerClass), 156 new Subtract(m_gpconf, CommandGene.IntegerClass), 157 new Push(m_gpconf, CommandGene.IntegerClass), 158 } 159 }; 160 m_gpconf.setRandomGenerator(new StockRandomGenerator()); 161 try { 162 gppop.create(types, argTypes, nodeSets, new int[] {1}, new int[] {1}, 3, 163 true, 10, new boolean[] {true}); 164 fail(); 165 } catch (IllegalStateException iex) { 166 ; } 168 } 169 170 176 public void testSerialize_0() 177 throws Exception { 178 GPPopulation pop = new GPPopulation(m_gpconf, 2); 179 GPProgram prog = new GPProgram(m_gpconf, 2); 180 ProgramChromosome chrom = new ProgramChromosome(m_gpconf, 2, prog); 181 prog.setChromosome(0, chrom); 182 prog.setChromosome(1, chrom); 183 pop.setGPProgram(0, prog); 184 pop.setGPProgram(1, prog); 185 GPPopulation pop2 = (GPPopulation)doSerialize(pop); 188 assertEquals(pop, pop2); 189 } 190 } 191 | Popular Tags |