1 10 package org.jgap.impl; 11 12 import org.jgap.*; 13 import org.jgap.event.*; 14 import junit.framework.*; 15 16 22 public class DefaultConfigurationTest 23 extends JGAPTestCase { 24 25 private final static String CVS_REVISION = "$Revision: 1.16 $"; 26 27 public static Test suite() { 28 TestSuite suite = new TestSuite(DefaultConfigurationTest.class); 29 return suite; 30 } 31 32 36 public void testConstruct_0() { 37 assertEquals(EventManager.class, conf.getEventManager().getClass()); 38 assertEquals(DefaultFitnessEvaluator.class, 39 conf.getFitnessEvaluator().getClass()); 40 assertEquals(BestChromosomesSelector.class, 41 conf.getNaturalSelectors(true).get(0).getClass()); 42 assertEquals(StockRandomGenerator.class, 43 conf.getRandomGenerator().getClass()); 44 assertEquals(ChromosomePool.class, conf.getChromosomePool().getClass()); 45 assertEquals(2, conf.getGeneticOperators().size()); 46 int code = 0; 48 GeneticOperator op; 49 for (int i = 0; i < 2; i++) { 50 op = (GeneticOperator) conf.getGeneticOperators().get(i); 51 if (op instanceof MutationOperator) { 52 code = code ^ 1; 53 } 54 else if (op instanceof CrossoverOperator) { 58 code = code ^ 4; 59 } 60 } 61 assertEquals(5, code); 62 } 63 64 70 public void testConstruct_1() { 71 try { 72 Configuration conf = new DefaultConfigForTest(); 73 fail(); 74 } 75 catch (RuntimeException rex) { 76 ; } 78 } 79 80 86 public void testConstruct_2() 87 throws Exception { 88 DefaultConfiguration.reset(); 89 DefaultConfiguration conf = new DefaultConfiguration(); 90 assertEquals("", conf.getId()); 91 assertEquals("", conf.getName()); 92 } 93 94 100 public void testConstruct_3() 101 throws Exception { 102 DefaultConfiguration.reset(); 103 DefaultConfiguration conf = new DefaultConfiguration("xxX1","3a"); 104 assertEquals("xxX1", conf.getId()); 105 assertEquals("3a", conf.getName()); 106 } 107 108 class DefaultConfigForTest 109 extends DefaultConfiguration { 110 public void setRandomGenerator(RandomGenerator a_generatorToSet) 111 throws InvalidConfigurationException { 112 throw new InvalidConfigurationException("For Test only"); 113 } 114 } 115 } 116 | Popular Tags |