1 10 package org.jgap.impl; 11 12 import java.util.*; 13 import org.jgap.*; 14 import junit.framework.*; 15 16 22 public class DefaultCompareToHandlerTest 23 extends JGAPTestCase { 24 25 private static final String CVS_REVISION = "$Revision: 1.1 $"; 26 27 public static Test suite() { 28 TestSuite suite = new TestSuite(DefaultCompareToHandlerTest.class); 29 return suite; 30 } 31 32 38 public void testIsHandlerFor_0() 39 throws Exception { 40 IHandler handler = new DefaultCompareToHandler(); 41 assertFalse(handler.isHandlerFor(null, null)); 42 } 43 44 50 public void testIsHandlerFor_1() 51 throws Exception { 52 IHandler handler = new DefaultCompareToHandler(); 53 assertTrue(handler.isHandlerFor(null, String .class)); 54 } 55 56 62 public void testIsHandlerFor_3() 63 throws Exception { 64 IHandler handler = new DefaultCompareToHandler(); 65 String v = "Test"; 66 assertTrue(handler.isHandlerFor(v, null)); 67 } 68 69 75 public void testPerform_1() 76 throws Exception { 77 IHandler handler = new DefaultCompareToHandler(); 78 FixedBinaryGene f1 = new FixedBinaryGene(conf, 3); 79 Integer result = (Integer ) handler.perform(f1, FixedBinaryGene.class, null); 80 assertEquals(1, result.intValue()); 81 } 82 83 89 public void testPerform_2() 90 throws Exception { 91 IHandler handler = new DefaultCompareToHandler(); 92 FixedBinaryGene f1 = new FixedBinaryGene(conf, 3); 93 FixedBinaryGene f2 = new FixedBinaryGene(conf, 5); 94 Integer result = (Integer ) handler.perform(f1, FixedBinaryGene.class, f2); 95 assertEquals(-1, result.intValue()); 96 } 97 98 104 public void testIsHandlerFor_2() 105 throws Exception { 106 IHandler handler = new DefaultCompareToHandler(); 107 Object app = new MyAppDataForTest(); 108 assertTrue(handler.isHandlerFor(app, null)); 109 assertTrue(handler.isHandlerFor(app, app.getClass())); 110 } 111 112 class MyAppDataForTest 113 implements Comparable { 114 public int compareTo(Object o) { 115 return 0; 116 } 117 } 118 } 119 | Popular Tags |