1 10 package org.jgap; 11 12 import junit.framework.*; 13 14 20 public class FitnessFunctionTest 21 extends JGAPTestCase { 22 23 private final static String CVS_REVISION = "$Revision: 1.14 $"; 24 25 public static Test suite() { 26 TestSuite suite = new TestSuite(FitnessFunctionTest.class); 27 return suite; 28 } 29 30 public void testGetFitnessValue_0() { 31 FitnessFunctionImpl fitfunc = new FitnessFunctionImpl(7); 32 assertEquals(7.0d, fitfunc.getFitnessValue(null), 0.00000001d); 33 } 34 35 public void testGetFitnessValue_1() { 36 try { 37 FitnessFunctionImpl fitfunc = new FitnessFunctionImpl( -7); 38 fitfunc.getFitnessValue(null); 39 fail(); 40 } 41 catch (RuntimeException cause) { 42 ; } 44 } 45 46 public void testGetFitnessValue_2() { 47 try { 48 FitnessFunctionImpl fitfunc = new FitnessFunctionImpl(0); 49 fitfunc.getFitnessValue(null); 50 } 51 catch (RuntimeException cause) { 52 ; } 54 } 55 56 62 public void testLastComputedValue_0() 63 throws Exception { 64 FitnessFunctionImpl fitfunc = new FitnessFunctionImpl(47.15d); 65 assertEquals(FitnessFunction.NO_FITNESS_VALUE, 66 fitfunc.getLastComputedFitnessValue(), DELTA); 67 IChromosome chrom = new Chromosome(new ConfigurationForTest()); 68 fitfunc.getFitnessValue(chrom); 69 assertEquals(47.15d, fitfunc.getLastComputedFitnessValue(), DELTA); 70 } 71 72 78 private class FitnessFunctionImpl 79 extends FitnessFunction { 80 83 private double m_evaluationValue; 84 85 public FitnessFunctionImpl(double a_evaluationValue) { 86 m_evaluationValue = a_evaluationValue; 87 } 88 89 protected double evaluate(IChromosome a_subject) { 90 return m_evaluationValue; 91 } 92 } 93 } 94 | Popular Tags |