KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > audit > KeyedValues2DTest


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.audit;
11
12 import java.util.*;
13 import org.jgap.*;
14 import junit.framework.*;
15
16 /**
17  * Tests for KeyedValues2D class
18  *
19  * @author Klaus Meffert
20  * @since 3.0
21  */

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

42   public void testSerializable_0()
43       throws Exception JavaDoc {
44     KeyedValues2D kv = new KeyedValues2D();
45     Number JavaDoc value = new Double JavaDoc(4.5d);
46     Comparable JavaDoc key1 = new Double JavaDoc(0.3d);
47     Comparable JavaDoc key2 = new Double JavaDoc(-3.5d);
48     kv.setValue(value, key1, key2);
49     super.isSerializable(kv);
50   }
51
52   /**
53    * @throws Exception
54    *
55    * @author Klaus Meffert
56    * @since 3.0
57    */

58   public void testConstruct_0()
59       throws Exception JavaDoc {
60     KeyedValues2D kv = new KeyedValues2D();
61     assertEquals(0, kv.getRowCount());
62     assertEquals(0, kv.getColumnCount());
63   }
64
65   /**
66    * @throws Exception
67    *
68    * @author Klaus Meffert
69    * @since 3.0
70    */

71   public void testSetValue_0()
72       throws Exception JavaDoc {
73     KeyedValues2D kv = new KeyedValues2D(false);
74     Comparable JavaDoc row = new Integer JavaDoc(8);
75     Comparable JavaDoc col = new Integer JavaDoc(4);
76     Number JavaDoc value = new Double JavaDoc(4.5d);
77     kv.setValue(value, row, col);
78     Comparable JavaDoc row2 = new Integer JavaDoc(11);
79     Comparable JavaDoc col2 = new Integer JavaDoc(1);
80     Number JavaDoc value2 = new Double JavaDoc(9.0d);
81     kv.setValue(value2, row2, col2);
82     assertSame(row, kv.getRowKey(0));
83     assertSame(value, kv.getValue(row, col));
84     assertSame(row2, kv.getRowKey(1));
85     assertSame(value2, kv.getValue(row2, col2));
86   }
87
88   /**
89    * @throws Exception
90    *
91    * @author Klaus Meffert
92    * @since 3.0
93    */

94   public void testSetValue_02()
95       throws Exception JavaDoc {
96     KeyedValues2D kv = new KeyedValues2D(true);
97     Comparable JavaDoc row = new Integer JavaDoc(8);
98     Comparable JavaDoc col = new Integer JavaDoc(4);
99     Number JavaDoc value = new Double JavaDoc(4.5d);
100     kv.setValue(value, row, col);
101     Comparable JavaDoc row2 = new Integer JavaDoc(11);
102     Comparable JavaDoc col2 = new Integer JavaDoc(1);
103     Number JavaDoc value2 = new Double JavaDoc(9.0d);
104     kv.setValue(value2, row2, col2);
105     assertSame(row, kv.getRowKey(0));
106     assertSame(value, kv.getValue(row, col));
107     assertSame(row2, kv.getRowKey(1));
108     assertSame(value2, kv.getValue(row2, col2));
109   }
110
111   /**
112    * @throws Exception
113    *
114    * @author Klaus Meffert
115    * @since 3.0
116    */

117   public void testSetValue_1()
118       throws Exception JavaDoc {
119     KeyedValues2D kv = new KeyedValues2D();
120     Comparable JavaDoc col = new Integer JavaDoc(4);
121     Number JavaDoc value = new Double JavaDoc(4.5d);
122     kv.setValue(value, null, col);
123     assertEquals(value, kv.getValue(0, 0));
124   }
125
126   /**
127    * @throws Exception
128    *
129    * @author Klaus Meffert
130    * @since 3.0
131    */

132   public void testSetValue_2()
133       throws Exception JavaDoc {
134     KeyedValues2D kv = new KeyedValues2D();
135     Comparable JavaDoc row = new Integer JavaDoc(4);
136     Number JavaDoc value = new Double JavaDoc(4.5d);
137     kv.setValue(value, row, null);
138     assertEquals(null, kv.getValue(0, 0));
139   }
140
141   /**
142    * @throws Exception
143    *
144    * @author Klaus Meffert
145    * @since 3.0
146    */

147   public void testSetValue_3()
148       throws Exception JavaDoc {
149     KeyedValues2D kv = new KeyedValues2D();
150     Comparable JavaDoc row = new Integer JavaDoc(4);
151     Number JavaDoc value = new Double JavaDoc(4.5d);
152     kv.setValue(value, row, null);
153     value = new Double JavaDoc(11.8d);
154     kv.setValue(value, row, null);
155     assertEquals(null, kv.getValue(0, 0));
156   }
157
158   /**
159    * @throws Exception
160    *
161    * @author Klaus Meffert
162    * @since 3.0
163    */

164   public void testGetValue_0()
165       throws Exception JavaDoc {
166     KeyedValues2D kv = new KeyedValues2D();
167     Comparable JavaDoc col = new Integer JavaDoc(4);
168     Number JavaDoc value = new Double JavaDoc(4.5d);
169     assertEquals(null, kv.getValue(col, col));
170   }
171
172   /**
173    * @throws Exception
174    *
175    * @author Klaus Meffert
176    * @since 3.0
177    */

178   public void testClone_0()
179       throws Exception JavaDoc {
180     KeyedValues2D kv = new KeyedValues2D();
181     Number JavaDoc value = new Double JavaDoc(4.5d);
182     Comparable JavaDoc rowkey = new Double JavaDoc(2.3d);
183     Comparable JavaDoc colkey = new Double JavaDoc(-7.82d);
184     kv.setValue(value, rowkey, colkey);
185     KeyedValues2D clone = (KeyedValues2D) kv.clone();
186     assertEquals(clone, kv);
187     assertSame(kv.getRowKey(0), clone.getRowKey(0));
188     assertSame(kv.getColumnKey(0), clone.getColumnKey(0));
189     assertSame(kv.getValue(0,0), clone.getValue(0,0));
190   }
191
192   /**
193    * @throws Exception
194    *
195    * @author Klaus Meffert
196    * @since 3.0
197    */

198   public void testEquals_0()
199       throws Exception JavaDoc {
200     KeyedValues2D kv = new KeyedValues2D();
201     assertFalse(kv.equals(null));
202     assertTrue(kv.equals(kv));
203     assertFalse(kv.equals(new Vector()));
204   }
205
206   /**
207    * @throws Exception
208    *
209    * @author Klaus Meffert
210    * @since 3.0
211    */

212   public void testEquals_1()
213       throws Exception JavaDoc {
214     KeyedValues2D kv = new KeyedValues2D();
215     Number JavaDoc value = new Double JavaDoc(4.5d);
216     Comparable JavaDoc rowkey = new Double JavaDoc(12.3d);
217     Comparable JavaDoc colkey = new Double JavaDoc(92.3d);
218     kv.setValue(value, rowkey, colkey);
219     KeyedValues2D kv2 = new KeyedValues2D();
220     assertFalse(kv.equals(kv2));
221     assertFalse(kv2.equals(kv));
222   }
223
224   /**
225    * @throws Exception
226    *
227    * @author Klaus Meffert
228    * @since 3.0
229    */

230   public void testEquals_2()
231       throws Exception JavaDoc {
232     KeyedValues2D kv = new KeyedValues2D();
233     Number JavaDoc value = new Double JavaDoc(4.5d);
234     Comparable JavaDoc rowkey = new Double JavaDoc(12.3d);
235     Comparable JavaDoc colkey = new Double JavaDoc(92.3d);
236     kv.setValue(value, rowkey, colkey);
237     KeyedValues2D kv2 = new KeyedValues2D();
238     Comparable JavaDoc colkey2 = new Double JavaDoc(17.9d);
239     kv2.setValue(value, rowkey, colkey2);
240     assertFalse(kv.equals(kv2));
241     assertFalse(kv2.equals(kv));
242   }
243
244   /**
245    * @throws Exception
246    *
247    * @author Klaus Meffert
248    * @since 3.0
249    */

250   public void testEquals_3()
251       throws Exception JavaDoc {
252     KeyedValues2D kv = new KeyedValues2D();
253     Number JavaDoc value = new Double JavaDoc(4.5d);
254     Comparable JavaDoc rowkey = new Double JavaDoc(12.3d);
255     Comparable JavaDoc colkey = new Double JavaDoc(92.3d);
256     kv.setValue(value, rowkey, colkey);
257     KeyedValues2D kv2 = new KeyedValues2D();
258     Number JavaDoc value2 = null;
259     kv2.setValue(value2, rowkey, colkey);
260     assertFalse(kv.equals(kv2));
261     assertFalse(kv2.equals(kv));
262   }
263
264   /**
265    * @throws Exception
266    *
267    * @author Klaus Meffert
268    * @since 3.0
269    */

270   public void testEquals_4()
271       throws Exception JavaDoc {
272     KeyedValues2D kv = new KeyedValues2D();
273     Number JavaDoc value = null;
274     Comparable JavaDoc rowkey = new Double JavaDoc(12.3d);
275     Comparable JavaDoc colkey = new Double JavaDoc(92.3d);
276     kv.setValue(value, rowkey, colkey);
277     KeyedValues2D kv2 = new KeyedValues2D();
278     kv2.setValue(value, rowkey, colkey);
279     assertTrue(kv.equals(kv2));
280   }
281
282 }
283
Popular Tags