1 10 package org.jgap.impl.fitness; 11 12 import java.util.*; 13 import junit.framework.*; 14 import org.jgap.*; 15 16 22 public class TruthTableFitnessFunctionTest 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(TruthTableFitnessFunctionTest.class); 29 return suite; 30 } 31 32 38 public void testCalcFitness_0() 39 throws Exception { 40 Map inout = new HashMap(); 41 inout.put(new Double (2), new Double (3)); 42 inout.put(new Double (9), new Double (11)); 43 TruthTableFitnessFunctionImpl fitfunc = new TruthTableFitnessFunctionImpl( 44 conf, 7); 45 Map truthTable = new HashMap(); 46 truthTable.put(new Double (2), new Double (4)); 47 truthTable.put(new Double (8), new Double (1)); 48 truthTable.put(new Double (9), new Double (11)); 49 fitfunc.setTruthTable(truthTable); 50 assertEquals(2.0d, fitfunc.calcFitness(inout), DELTA); 51 } 52 53 59 public void testCalcFitness_1() 60 throws Exception { 61 Map inout = new HashMap(); 62 inout.put(new Double (2), new Double (3)); 63 inout.put(new Double (9), new Double (11)); 64 Map truthTable = new HashMap(); 65 truthTable.put(new Double (2), new Double (4)); 66 truthTable.put(new Double (8), new Double (1)); 67 truthTable.put(new Double (9), new Double (11)); 68 TruthTableFitnessFunctionImpl fitfunc = new TruthTableFitnessFunctionImpl( 69 conf, 7, truthTable); 70 assertEquals(2.0d, fitfunc.calcFitness(inout), DELTA); 71 } 72 73 80 public void testCalcFitness_2() 81 throws Exception { 82 Map inout = new HashMap(); 83 inout.put(new Double (2), new Double (Double.NaN)); 84 inout.put(new Double (9), new Double (11)); 85 Map truthTable = new HashMap(); 86 truthTable.put(new Double (2), new Double (4)); 87 truthTable.put(new Double (8), new Double (1)); 88 TruthTableFitnessFunctionImpl fitfunc = new TruthTableFitnessFunctionImpl( 89 conf, 7, truthTable); 90 assertTrue(Double.isNaN(fitfunc.calcFitness(inout))); 91 } 92 93 99 public void testgetConfiguration_0() 100 throws Exception { 101 Map truthTable = new HashMap(); 102 truthTable.put(new Double (9), new Double (11)); 103 TruthTableFitnessFunctionImpl fitfunc = new TruthTableFitnessFunctionImpl( 104 conf, 7, truthTable); 105 assertSame(conf, fitfunc.getConfiguration()); 106 } 107 108 114 public void testConstruct_0() 115 throws Exception { 116 Genotype.setStaticConfiguration(conf); 117 TruthTableFitnessFunctionImpl fitfunc = new TruthTableFitnessFunctionImpl(); 118 assertSame(conf, fitfunc.getConfiguration()); 119 } 120 121 127 private class TruthTableFitnessFunctionImpl 128 extends TruthTableFitnessFunction { 129 132 private double m_evaluationValue; 133 134 public TruthTableFitnessFunctionImpl() { 135 super(); 136 } 137 138 public TruthTableFitnessFunctionImpl(Configuration a_config, 139 double a_evaluationValue, Map a_values) { 140 super(a_config, a_values); 141 m_evaluationValue = a_evaluationValue; 142 } 143 144 public TruthTableFitnessFunctionImpl(Configuration a_config, 145 double a_evaluationValue) { 146 super(a_config); 147 m_evaluationValue = a_evaluationValue; 148 } 149 150 protected double evaluate(IChromosome a_subject) { 151 return m_evaluationValue; 152 } 153 } 154 } 155 | Popular Tags |