|
TestFeatureMap |
|
1 package gate.util; 2 3 import junit.framework.*; 4 5 /** 6 * Title: Gate2 7 * Description: 8 * Copyright: Copyright (c) 2000 9 * Company: University Of Sheffield 10 * @author 11 * @version 1.0 12 */ 13 14 public class TestFeatureMap extends TestCase { 15 16 /** Debug flag */ 17 private static final boolean DEBUG = false; 18 19 /** Construction */ 20 public TestFeatureMap(String name) { super(name); } 21 22 /** Test the testPutAndGet()... methods. */ 23 public void testPutAndGet() throws Exception { 24 assertTrue(true); 25 SimpleFeatureMapImpl map = new SimpleFeatureMapImpl(); 26 map.put("1", "bala"); 27 map.put("1", "bala2"); 28 map.put("2", "20"); 29 map.put("3", null); 30 map.put(null, "5"); 31 32 Object value = null; 33 /** 34 * test1: 35 * get replaced value by normal key 36 */ 37 value = map.get("1"); 38 assertSame(value, "bala2"); 39 /** 40 * test 2: 41 * get normal value by normal key 42 */ 43 value = map.get("2"); 44 assertSame(value, "20"); 45 /** 46 * Test 3: 47 * get null value by the key 48 */ 49 value = map.get("3"); 50 assertSame(value, null); 51 /** 52 * test 4: 53 * try to get value by 'null' key 54 */ 55 value = map.get(null); 56 assertSame(value, "5"); 57 } // testPutAndGet() 58 59 public void testSubsume() throws Exception { 60 assertTrue(true); 61 SimpleFeatureMapImpl map = new SimpleFeatureMapImpl(); 62 SimpleFeatureMapImpl map2 = new SimpleFeatureMapImpl(); 63 map.put("1", "bala"); 64 map2.put("1", map.get("1")); 65 66 map.put("2", "20"); 67 /** 68 * test1: 69 * subsume partially - map1 and map2 has one common element 70 */ 71 assertTrue(map.subsumes(map2)); 72 /** 73 * test 2: 74 * map2 do NOT subsumes map1 75 */ 76 assertTrue(!map2.subsumes(map)); 77 /** 78 * Test 3: 79 * subsume partially - map1 and map2.keySet() 80 */ 81 assertTrue(map.subsumes(map2, map2.keySet())); 82 /** 83 * test 4: 84 * map2 SUBSUMES and map using the map2.keySet() 85 */ 86 assertTrue(map2.subsumes(map, map2.keySet())); 87 88 /** 89 * test 5,6,7,8: 90 * test1,2,3,4 with NULL's in the map and 91 * not NULL's the map2 under the same key "3" 92 */ 93 map.put("3", null); 94 map2.put("3", "not null"); 95 96 assertTrue(!map.subsumes(map2)); 97 assertTrue(!map2.subsumes(map)); 98 assertTrue(!map.subsumes(map2, map2.keySet())); 99 assertTrue(!map2.subsumes(map, map2.keySet())); 100 101 /** 102 * Test 9,10,11,12 repeat the same test but with compatible (null) values 103 * under the same key "3" 104 */ 105 map2.put("3", null); 106 107 assertTrue(map.subsumes(map2)); 108 assertTrue(!map2.subsumes(map)); 109 assertTrue(map.subsumes(map2, map2.keySet())); 110 assertTrue(map2.subsumes(map, map2.keySet())); 111 112 /** 113 * Test 13,14,15,16 repeat the same test but with null keys in the two of the maps 114 */ 115 map.put(null, "5"); 116 map2.put(null, "5"); 117 118 assertTrue(map.subsumes(map2)); 119 assertTrue(!map2.subsumes(map)); 120 assertTrue(map.subsumes(map2, map2.keySet())); 121 assertTrue(map2.subsumes(map, map2.keySet())); 122 } // testSubsume() 123 124 /** Test suite routine for the test runner */ 125 public static Test suite() { 126 return new TestSuite(TestFeatureMap.class); 127 } // suite 128 129 public static void main(String args[]){ 130 TestFeatureMap app = new TestFeatureMap("TestFeatureMap"); 131 try { 132 app.testPutAndGet(); 133 app.testSubsume(); 134 } catch (Exception e) { 135 e.printStackTrace (Err.getPrintWriter()); 136 } 137 } // main 138 } // TestFeatureMap
|
TestFeatureMap |
|