KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > distr > CultureMemoryCellTest


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

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

36   public void testToString_0() {
37     CultureMemoryCell cell = new CultureMemoryCell("aName", 77);
38     assertEquals("[Name:aName;Value:null;Version:0;Read accessed:0;"
39                  + "History Size:77;History:[]",
40                  cell.toString());
41     cell.setDouble(45.9d);
42     String JavaDoc result = cell.toString();
43     assertEquals(
44         "[Name:aName;Value:45.9;Version:1;Read accessed:0;History Size:77;"
45         + "History:[[Name:aName;Value:45.9;Version:0;Read accessed:0;"
46         + "History Size:77;History:[]]]", result);
47   }
48
49   /**
50    * @author Klaus Meffert
51    * @since 2.3
52    */

53   public void testToString_1() {
54     CultureMemoryCell cell = new CultureMemoryCell("aName", 77);
55     assertEquals("[Name:aName;Value:null;Version:0;Read accessed:0;"
56                  + "History Size:77;History:[]",
57                  cell.toString());
58     cell.setDouble(17.3d);
59     cell.setDouble( -45.9d);
60     String JavaDoc result = cell.toString();
61     assertEquals(
62         "[Name:aName;Value:-45.9;Version:2;Read accessed:0;History Size:77;"
63         + "History:[[Name:aName;Value:17.3;Version:0;Read accessed:0;"
64         + "History Size:77;History:[]];[Name:aName;Value:-45.9;Version:1;"
65         + "Read accessed:0;History Size:77;History:[]]]", result);
66   }
67
68   /**
69    * Empty cell.
70    *
71    * @author Klaus Meffert
72    * @since 2.3
73    */

74   public void testToString_2() {
75     CultureMemoryCell cell = new CultureMemoryCell();
76     assertEquals("[Name:null;Value:null;Version:0;Read accessed:0;"
77                  + "History Size:3;History:[]",
78                  cell.toString());
79   }
80
81   /**
82    * @author Klaus Meffert
83    * @since 2.3
84    */

85   public void testSetDouble_0() {
86     CultureMemoryCell cell = new CultureMemoryCell("ANAME", 55);
87     cell.setDouble(17.3d);
88     assertEquals(17.3d, cell.getCurrentValueAsDouble(), DELTA);
89     cell.setDouble(1.8d);
90     assertEquals(1.8d, ( (Double JavaDoc) cell.getCurrentValue()).doubleValue(), DELTA);
91   }
92
93   /*
94    * Tests main functionality of CultureMemoryCell.
95    *
96    * @author Klaus Meffert
97    * @since 2.3
98    */

99   public void testSetValue_0() {
100     CultureMemoryCell cell = new CultureMemoryCell("aname", 3);
101     assertEquals(0, cell.getVersion());
102     cell.setValue(new Integer JavaDoc(15));
103     assertEquals(1, cell.getVersion());
104     assertEquals(15, ( (Integer JavaDoc) cell.getCurrentValue()).intValue());
105     assertEquals(1, cell.getReadAccessed());
106     cell.setValue(new Integer JavaDoc(29));
107     assertEquals(2, cell.getVersion());
108     assertEquals(29, ( (Integer JavaDoc) cell.getCurrentValue()).intValue());
109     assertEquals(2, cell.getReadAccessed());
110     List history = cell.getHistory();
111     assertEquals(2, history.size());
112     CultureMemoryCell c1 = (CultureMemoryCell) history.get(0);
113     assertEquals(15, ( (Integer JavaDoc) c1.getCurrentValue()).intValue());
114     c1 = (CultureMemoryCell) history.get(1);
115     assertEquals(29, ( (Integer JavaDoc) c1.getCurrentValue()).intValue());
116     cell.setValue(new Integer JavaDoc(42));
117     history = cell.getHistory();
118     assertEquals(3, history.size());
119     c1 = (CultureMemoryCell) history.get(0);
120     assertEquals(15, ( (Integer JavaDoc) c1.getCurrentValue()).intValue());
121     c1 = (CultureMemoryCell) history.get(1);
122     assertEquals(29, ( (Integer JavaDoc) c1.getCurrentValue()).intValue());
123     c1 = (CultureMemoryCell) history.get(2);
124     assertEquals(42, ( (Integer JavaDoc) c1.getCurrentValue()).intValue());
125     cell.setValue(new Integer JavaDoc(33));
126     assertEquals(3, history.size());
127     c1 = (CultureMemoryCell) history.get(0);
128     assertEquals(29, ( (Integer JavaDoc) c1.getCurrentValue()).intValue());
129     c1 = (CultureMemoryCell) history.get(1);
130     assertEquals(42, ( (Integer JavaDoc) c1.getCurrentValue()).intValue());
131     c1 = (CultureMemoryCell) history.get(2);
132     assertEquals(33, ( (Integer JavaDoc) c1.getCurrentValue()).intValue());
133   }
134
135   /**
136    * @throws Exception
137    *
138    * @author Klaus Meffert
139    * @since 3.0
140    */

141   public void testSerialize_0()
142       throws Exception JavaDoc {
143     CultureMemoryCell cell = new CultureMemoryCell("ANAME", 55);
144     cell.setDouble(17.3d);
145     CultureMemoryCell cell2 = (CultureMemoryCell) doSerialize(cell);
146     assertEquals(cell, cell2);
147   }
148
149 }
150
Popular Tags