1 18 19 package org.sablecc.sablecc.alphabet; 20 21 import static org.junit.Assert.assertEquals; 22 import static org.junit.Assert.fail; 23 24 import java.math.BigInteger ; 25 26 import org.junit.Test; 27 import org.sablecc.sablecc.exception.InternalException; 28 29 public class AdjacencyRealmTest { 30 31 private Interval<Integer > intervalInteger; 33 34 private Interval<BigInteger > intervalBigInt; 35 36 @Test 37 public void testMin() { 38 39 43 Integer intBound1; 44 Integer intBound2; 45 46 intBound1 = null; 48 intBound2 = 0; 49 try { 50 AdjacencyRealm.min(intBound1, intBound2); 51 fail("An InternalException should be thrown for a null bound."); 52 53 } 54 catch (InternalException e) { 55 } 57 58 intBound1 = 0; 60 intBound2 = null; 61 try { 62 AdjacencyRealm.min(intBound1, intBound2); 63 fail("An InternalException should be thrown for a null bound."); 64 65 } 66 catch (InternalException e) { 67 } 69 70 intBound1 = null; 72 intBound2 = null; 73 try { 74 AdjacencyRealm.min(intBound1, intBound2); 75 fail("An InternalException should be thrown for a null bound."); 76 77 } 78 catch (InternalException e) { 79 } 81 82 intBound1 = 10; 84 intBound2 = 1; 85 try { 86 assertEquals("bound2 not returned when bound1 > bound2", intBound2, 87 AdjacencyRealm.min(intBound1, intBound2)); 88 } 89 catch (InternalException e) { 90 fail("An InternalException should not be thrown for non-null bounds."); 91 } 92 93 intBound1 = 1; 95 intBound2 = 10; 96 try { 97 assertEquals("bound1 not returned when bound1 < bound2", intBound1, 98 AdjacencyRealm.min(intBound1, intBound2)); 99 } 100 catch (InternalException e) { 101 fail("An InternalException should not be thrown for non-null bounds."); 102 } 103 104 intBound1 = 10; 106 intBound2 = 10; 107 try { 108 assertEquals("bound2 not returned when bound1 = bound2", intBound2, 109 AdjacencyRealm.min(intBound1, intBound2)); 110 } 111 catch (InternalException e) { 112 fail("An InternalException should not be thrown for non-null bounds."); 113 } 114 115 119 String stringBound1; 120 String stringBound2; 121 122 stringBound1 = null; 124 stringBound2 = "aaa"; 125 try { 126 AdjacencyRealm.min(stringBound1, stringBound2); 127 fail("An InternalException should be thrown for a null bound."); 128 129 } 130 catch (InternalException e) { 131 } 133 134 stringBound1 = "aaa"; 136 stringBound2 = null; 137 try { 138 AdjacencyRealm.min(stringBound1, stringBound2); 139 fail("An InternalException should be thrown for a null bound."); 140 141 } 142 catch (InternalException e) { 143 } 145 146 stringBound1 = null; 148 stringBound2 = null; 149 try { 150 AdjacencyRealm.min(stringBound1, stringBound2); 151 fail("An InternalException should be thrown for a null bound."); 152 153 } 154 catch (InternalException e) { 155 } 157 158 stringBound1 = "ccc"; 160 stringBound2 = "aaa"; 161 try { 162 assertEquals("bound2 not returned when bound1 > bound2", 163 stringBound2, AdjacencyRealm 164 .min(stringBound1, stringBound2)); 165 } 166 catch (InternalException e) { 167 fail("An InternalException should not be thrown for non-null bounds."); 168 } 169 170 stringBound1 = "aaa"; 172 stringBound2 = "ccc"; 173 try { 174 assertEquals("bound1 not returned when bound1 < bound2", 175 stringBound1, AdjacencyRealm 176 .min(stringBound1, stringBound2)); 177 } 178 catch (InternalException e) { 179 fail("An InternalException should not be thrown for non-null bounds."); 180 } 181 182 stringBound1 = "ccc"; 184 stringBound2 = "ccc"; 185 try { 186 assertEquals("bound2 not returned when bound1 = bound2", 187 stringBound2, AdjacencyRealm 188 .min(stringBound1, stringBound2)); 189 } 190 catch (InternalException e) { 191 fail("An InternalException should not be thrown for non-null bounds."); 192 } 193 194 } 195 196 @Test 197 public void testMax() { 198 199 203 Integer intBound1; 204 Integer intBound2; 205 206 intBound1 = null; 208 intBound2 = 0; 209 try { 210 AdjacencyRealm.max(intBound1, intBound2); 211 fail("An InternalException should be thrown for a null bound."); 212 213 } 214 catch (InternalException e) { 215 } 217 218 intBound1 = 0; 220 intBound2 = null; 221 try { 222 AdjacencyRealm.max(intBound1, intBound2); 223 fail("An InternalException should be thrown for a null bound."); 224 225 } 226 catch (InternalException e) { 227 } 229 230 intBound1 = null; 232 intBound2 = null; 233 try { 234 AdjacencyRealm.max(intBound1, intBound2); 235 fail("An InternalException should be thrown for a null bound."); 236 237 } 238 catch (InternalException e) { 239 } 241 242 intBound1 = 10; 244 intBound2 = 1; 245 try { 246 assertEquals("bound1 not returned when bound1 > bound2", intBound1, 247 AdjacencyRealm.max(intBound1, intBound2)); 248 } 249 catch (InternalException e) { 250 fail("An InternalException should not be thrown for non-null bounds."); 251 } 252 253 intBound1 = 1; 255 intBound2 = 10; 256 try { 257 assertEquals("bound2 not returned when bound1 < bound2", intBound2, 258 AdjacencyRealm.max(intBound1, intBound2)); 259 } 260 catch (InternalException e) { 261 fail("An InternalException should not be thrown for non-null bounds."); 262 } 263 264 intBound1 = 10; 266 intBound2 = 10; 267 try { 268 assertEquals("bound2 not returned when bound1 = bound2", intBound2, 269 AdjacencyRealm.max(intBound1, intBound2)); 270 } 271 catch (InternalException e) { 272 fail("An InternalException should not be thrown for non-null bounds."); 273 } 274 275 279 String stringBound1; 280 String stringBound2; 281 282 stringBound1 = null; 284 stringBound2 = "aaa"; 285 try { 286 AdjacencyRealm.max(stringBound1, stringBound2); 287 fail("An InternalException should be thrown for a null bound."); 288 289 } 290 catch (InternalException e) { 291 } 293 294 stringBound1 = "aaa"; 296 stringBound2 = null; 297 try { 298 AdjacencyRealm.max(stringBound1, stringBound2); 299 fail("An InternalException should be thrown for a null bound."); 300 301 } 302 catch (InternalException e) { 303 } 305 306 stringBound1 = null; 308 stringBound2 = null; 309 try { 310 AdjacencyRealm.max(stringBound1, stringBound2); 311 fail("An InternalException should be thrown for a null bound."); 312 313 } 314 catch (InternalException e) { 315 } 317 318 stringBound1 = "ccc"; 320 stringBound2 = "aaa"; 321 try { 322 assertEquals("bound1 not returned when bound1 > bound2", 323 stringBound1, AdjacencyRealm 324 .max(stringBound1, stringBound2)); 325 } 326 catch (InternalException e) { 327 fail("An InternalException should not be thrown for non-null bounds."); 328 } 329 330 stringBound1 = "aaa"; 332 stringBound2 = "ccc"; 333 try { 334 assertEquals("bound2 not returned when bound1 < bound2", 335 stringBound2, AdjacencyRealm 336 .max(stringBound1, stringBound2)); 337 } 338 catch (InternalException e) { 339 fail("An InternalException should not be thrown for non-null bounds."); 340 } 341 342 stringBound1 = "ccc"; 344 stringBound2 = "ccc"; 345 try { 346 assertEquals("bound2 not returned when bound1 = bound2", 347 stringBound2, AdjacencyRealm 348 .max(stringBound1, stringBound2)); 349 } 350 catch (InternalException e) { 351 fail("An InternalException should not be thrown for non-null bounds."); 352 } 353 354 } 355 356 @Test 357 public void testCreateIntervalTT() { 358 359 this.intervalInteger = new Interval<Integer >(0, 10, Realms.getInteger()); 361 Interval<Integer > createdIntervalInt = Realms.getInteger() 362 .createInterval(0, 10); 363 assertEquals( 364 "Created interval with integer (2 bounds) not the same as expected", 365 this.intervalInteger, createdIntervalInt); 366 367 this.intervalBigInt = new Interval<BigInteger >(new BigInteger ("1000"), 369 new BigInteger ("100000"), Realms.getBigInteger()); 370 Interval<BigInteger > createdIntervalBigInt = Realms.getBigInteger() 371 .createInterval(new BigInteger ("1000"), 372 new BigInteger ("100000")); 373 assertEquals( 374 "Created interval with big integer (2 bounds) not the same as expected", 375 this.intervalBigInt, createdIntervalBigInt); 376 } 377 378 @Test 379 public void testCreateIntervalT() { 380 381 this.intervalInteger = new Interval<Integer >(10, Realms.getInteger()); 383 Interval<Integer > createdIntervalInt = Realms.getInteger() 384 .createInterval(10); 385 assertEquals( 386 "Created interval with integer (1 bound) not the same as expected", 387 this.intervalInteger, createdIntervalInt); 388 389 this.intervalBigInt = new Interval<BigInteger >( 391 new BigInteger ("100000"), Realms.getBigInteger()); 392 Interval<BigInteger > createdIntervalBigInt = Realms.getBigInteger() 393 .createInterval(new BigInteger ("100000")); 394 assertEquals( 395 "Created interval with big integer (1 bound) not the same as expected", 396 this.intervalBigInt, createdIntervalBigInt); 397 398 } 399 400 } 401 | Popular Tags |