1 10 package org.jgap.distr; 11 12 import java.util.*; 13 import org.jgap.*; 14 import junit.framework.*; 15 16 22 public class CultureMemoryCellTest 23 extends JGAPTestCase { 24 25 private static final String CVS_REVISION = "$Revision: 1.10 $"; 26 27 public static Test suite() { 28 TestSuite suite = new TestSuite(CultureMemoryCellTest.class); 29 return suite; 30 } 31 32 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 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 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 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 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 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 ) cell.getCurrentValue()).doubleValue(), DELTA); 91 } 92 93 99 public void testSetValue_0() { 100 CultureMemoryCell cell = new CultureMemoryCell("aname", 3); 101 assertEquals(0, cell.getVersion()); 102 cell.setValue(new Integer (15)); 103 assertEquals(1, cell.getVersion()); 104 assertEquals(15, ( (Integer ) cell.getCurrentValue()).intValue()); 105 assertEquals(1, cell.getReadAccessed()); 106 cell.setValue(new Integer (29)); 107 assertEquals(2, cell.getVersion()); 108 assertEquals(29, ( (Integer ) 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 ) c1.getCurrentValue()).intValue()); 114 c1 = (CultureMemoryCell) history.get(1); 115 assertEquals(29, ( (Integer ) c1.getCurrentValue()).intValue()); 116 cell.setValue(new Integer (42)); 117 history = cell.getHistory(); 118 assertEquals(3, history.size()); 119 c1 = (CultureMemoryCell) history.get(0); 120 assertEquals(15, ( (Integer ) c1.getCurrentValue()).intValue()); 121 c1 = (CultureMemoryCell) history.get(1); 122 assertEquals(29, ( (Integer ) c1.getCurrentValue()).intValue()); 123 c1 = (CultureMemoryCell) history.get(2); 124 assertEquals(42, ( (Integer ) c1.getCurrentValue()).intValue()); 125 cell.setValue(new Integer (33)); 126 assertEquals(3, history.size()); 127 c1 = (CultureMemoryCell) history.get(0); 128 assertEquals(29, ( (Integer ) c1.getCurrentValue()).intValue()); 129 c1 = (CultureMemoryCell) history.get(1); 130 assertEquals(42, ( (Integer ) c1.getCurrentValue()).intValue()); 131 c1 = (CultureMemoryCell) history.get(2); 132 assertEquals(33, ( (Integer ) c1.getCurrentValue()).intValue()); 133 } 134 135 141 public void testSerialize_0() 142 throws Exception { 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 |