1 10 package org.jgap.distr; 11 12 import org.jgap.*; 13 import junit.framework.*; 14 15 21 public class CultureTest 22 extends JGAPTestCase { 23 24 private static final String CVS_REVISION = "$Revision: 1.14 $"; 25 26 public static Test suite() { 27 TestSuite suite = new TestSuite(CultureTest.class); 28 return suite; 29 } 30 31 35 public void testConstruct_0() { 36 try { 37 new Culture(0); 38 fail(); 39 } 40 catch (IllegalArgumentException iex) { 41 ; } 43 } 44 45 49 public void testConstruct_1() { 50 try { 51 new Culture( -3); 52 fail(); 53 } 54 catch (IllegalArgumentException iex) { 55 ; } 57 } 58 59 63 public void testConstruct_2() { 64 Culture c = new Culture(7); 65 assertEquals(7, c.size()); 66 } 67 68 74 public void testGet_0() { 75 try { 76 Culture c = new Culture(35); 77 c.set( -1, 2, 5, ""); 78 fail(); 79 } 80 catch (IllegalArgumentException iex) { 81 ; } 83 } 84 85 91 public void testGet_1() { 92 try { 93 Culture c = new Culture(35); 94 c.set(35, 2, 5, ""); 95 fail(); 96 } 97 catch (IllegalArgumentException iex) { 98 ; } 100 } 101 102 106 public void testGet_2() { 107 Culture c = new Culture(9); 108 CultureMemoryCell cell1 = c.set(3, 5.7d, 0, ""); 109 CultureMemoryCell cell = c.get(3); 110 assertSame(cell1, cell); 111 assertEquals(5.7d, cell.getCurrentValueAsDouble(), DELTA); 112 assertEquals(0, cell.getHistorySize()); 113 assertEquals("", cell.getName()); 114 } 115 116 120 public void testGet_3() { 121 Culture c = new Culture(9); 122 CultureMemoryCell cell1 = c.set(3, -5.7d, -1, null); 123 CultureMemoryCell cell = c.get(3); 124 assertSame(cell1, cell); 125 assertEquals( -5.7d, cell.getCurrentValueAsDouble(), DELTA); 126 assertEquals(0, cell.getHistorySize()); 127 assertEquals(null, cell.getName()); 128 } 129 130 134 public void testGet_4() { 135 Culture c = new Culture(11); 136 CultureMemoryCell cell1 = c.set(0, 0.0d, 17, "aName"); 137 CultureMemoryCell cell = c.get(0); 138 assertSame(cell1, cell); 139 assertEquals(0.0d, cell.getCurrentValueAsDouble(), DELTA); 140 assertEquals(17, cell.getHistorySize()); 141 assertEquals("aName", cell.getName()); 142 } 143 144 148 public void testGet_5() { 149 Culture c = new Culture(11); 150 CultureMemoryCell cell = c.get(7); 151 assertEquals(null, cell); 152 } 153 154 158 public void testToString_0() { 159 Culture c = new Culture(11); 160 String s = "["; 161 for (int i = 0; i < c.size(); i++) { 162 if (i > 0) { 163 s += ";"; 164 } 165 if (c.get(i) == null) { 166 s += "null"; 167 } 168 else { 169 s += c.get(i).toString(); 170 } 171 } 172 s += "]"; 173 assertEquals(s, c.toString()); 174 } 175 176 180 public void testToString_1() { 181 Culture c = new Culture(11); 182 c.set(1, 0.0d, 17, "aName"); 183 c.set(3, 23.5d, 5, "ANAME"); 184 c.set(4, 19.6d, 0, "aName"); 185 String s = "["; 186 for (int i = 0; i < c.size(); i++) { 187 if (i > 0) { 188 s += ";"; 189 } 190 if (c.get(i) == null) { 191 s += "null"; 192 } 193 else { 194 s += c.get(i).toString(); 195 } 196 } 197 s += "]"; 198 assertEquals(s, c.toString()); 199 } 200 201 207 public void testSerialize_0() 208 throws Exception { 209 Culture c = new Culture(11); 210 c.set(0, 2.3d, -1, "no name"); 211 Culture c2 = (Culture) doSerialize(c); 212 assertEquals(c, c2); 213 } 214 215 219 public void testClear_0() { 220 Culture c = new Culture(11); 221 c.set(1, 2.3d, -1, "no name"); 222 c.set("hallo", new Double (2.3d), -1); 223 c.clear(); 224 assertEquals(0, c.getMemoryNames().size()); 226 for (int i = 0; i < c.size(); i++) { 228 assertNull(c.get(i)); 229 } 230 } 231 232 236 public void testContains_0() { 237 Culture c = new Culture(11); 238 c.set("uniquename","value",-1); 239 assertTrue(c.contains("uniquename")); 240 assertFalse(c.contains("uniqueName")); 241 assertFalse(c.contains("UNIQUENAME")); 242 assertTrue(c.contains("uniquename")); 243 c.clear(); 244 assertFalse(c.contains("uniquename")); 245 } 246 247 251 public void testContains_1() { 252 Culture c = new Culture(7); 253 assertFalse(c.contains("uniquename")); 254 assertFalse(c.contains("*")); 255 assertFalse(c.contains("%")); 256 } 257 258 262 public void testContains_2() { 263 Culture c = new Culture(7); 264 try { 265 assertFalse(c.contains("")); 266 fail(); 267 }catch (IllegalArgumentException iex) { 268 ; } 270 } 271 272 276 public void testContains_3() { 277 Culture c = new Culture(7); 278 try { 279 assertFalse(c.contains(null)); 280 fail(); 281 }catch (IllegalArgumentException iex) { 282 ; } 284 } 285 } 286 | Popular Tags |