KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > impl > DefaultCompareToHandlerTest


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.impl;
11
12 import java.util.*;
13 import org.jgap.*;
14 import junit.framework.*;
15
16 /**
17  * Tests the DefaultCompareToHandler class.
18  *
19  * @author Klaus Meffert
20  * @since 3.1
21  */

22 public class DefaultCompareToHandlerTest
23     extends JGAPTestCase {
24   /** String containing the CVS revision. Read out via reflection!*/
25   private static final String JavaDoc CVS_REVISION = "$Revision: 1.1 $";
26
27   public static Test suite() {
28     TestSuite suite = new TestSuite(DefaultCompareToHandlerTest.class);
29     return suite;
30   }
31
32   /**
33    * @throws Exception
34    *
35    * @author Klaus Meffert
36    * @since 3.1
37    */

38   public void testIsHandlerFor_0()
39       throws Exception JavaDoc {
40     IHandler handler = new DefaultCompareToHandler();
41     assertFalse(handler.isHandlerFor(null, null));
42   }
43
44   /**
45    * @throws Exception
46    *
47    * @author Klaus Meffert
48    * @since 3.1
49    */

50   public void testIsHandlerFor_1()
51       throws Exception JavaDoc {
52     IHandler handler = new DefaultCompareToHandler();
53     assertTrue(handler.isHandlerFor(null, String JavaDoc.class));
54   }
55
56   /**
57    * @throws Exception
58    *
59    * @author Klaus Meffert
60    * @since 3.1
61    */

62   public void testIsHandlerFor_3()
63       throws Exception JavaDoc {
64     IHandler handler = new DefaultCompareToHandler();
65     String JavaDoc v = "Test";
66     assertTrue(handler.isHandlerFor(v, null));
67   }
68
69   /**
70    * @throws Exception
71    *
72    * @author Klaus Meffert
73    * @since 3.1
74    */

75   public void testPerform_1()
76       throws Exception JavaDoc {
77     IHandler handler = new DefaultCompareToHandler();
78     FixedBinaryGene f1 = new FixedBinaryGene(conf, 3);
79     Integer JavaDoc result = (Integer JavaDoc) handler.perform(f1, FixedBinaryGene.class, null);
80     assertEquals(1, result.intValue());
81   }
82
83   /**
84    * @throws Exception
85    *
86    * @author Klaus Meffert
87    * @since 3.1
88    */

89   public void testPerform_2()
90       throws Exception JavaDoc {
91     IHandler handler = new DefaultCompareToHandler();
92     FixedBinaryGene f1 = new FixedBinaryGene(conf, 3);
93     FixedBinaryGene f2 = new FixedBinaryGene(conf, 5);
94     Integer JavaDoc result = (Integer JavaDoc) handler.perform(f1, FixedBinaryGene.class, f2);
95     assertEquals(-1, result.intValue());
96   }
97
98   /**
99    * @throws Exception
100    *
101    * @author Klaus Meffert
102    * @since 3.1
103    */

104   public void testIsHandlerFor_2()
105       throws Exception JavaDoc {
106     IHandler handler = new DefaultCompareToHandler();
107     Object JavaDoc app = new MyAppDataForTest();
108     assertTrue(handler.isHandlerFor(app, null));
109     assertTrue(handler.isHandlerFor(app, app.getClass()));
110   }
111
112   class MyAppDataForTest
113       implements Comparable JavaDoc {
114     public int compareTo(Object JavaDoc o) {
115       return 0;
116     }
117   }
118 }
119
Popular Tags