001 package gate.util;
002
003 import junit.framework.*;
004
005 /**
006 * Title: Gate2
007 * Description:
008 * Copyright: Copyright (c) 2000
009 * Company: University Of Sheffield
010 * @version 1.0
011 */
012
013 public class TestFeatureMap extends TestCase {
014
015 /** Debug flag */
016 private static final boolean DEBUG = false;
017
018 /** Construction */
019 public TestFeatureMap(String name) { super(name); }
020
021 /** Test the testPutAndGet()... methods. */
022 public void testPutAndGet() throws Exception {
023 assertTrue(true);
024 SimpleFeatureMapImpl map = new SimpleFeatureMapImpl();
025 map.put("1", "bala");
026 map.put("1", "bala2");
027 map.put("2", "20");
028 map.put("3", null);
029 map.put(null, "5");
030
031 Object value = null;
032 /**
033 * test1:
034 * get replaced value by normal key
035 */
036 value = map.get("1");
037 assertSame(value, "bala2");
038 /**
039 * test 2:
040 * get normal value by normal key
041 */
042 value = map.get("2");
043 assertSame(value, "20");
044 /**
045 * Test 3:
046 * get null value by the key
047 */
048 value = map.get("3");
049 assertSame(value, null);
050 /**
051 * test 4:
052 * try to get value by 'null' key
053 */
054 value = map.get(null);
055 assertSame(value, "5");
056 } // testPutAndGet()
057
058 public void testSubsume() throws Exception {
059 assertTrue(true);
060 SimpleFeatureMapImpl map = new SimpleFeatureMapImpl();
061 SimpleFeatureMapImpl map2 = new SimpleFeatureMapImpl();
062 map.put("1", "bala");
063 map2.put("1", map.get("1"));
064
065 map.put("2", "20");
066 /**
067 * test1:
068 * subsume partially - map1 and map2 has one common element
069 */
070 assertTrue(map.subsumes(map2));
071 /**
072 * test 2:
073 * map2 do NOT subsumes map1
074 */
075 assertTrue(!map2.subsumes(map));
076 /**
077 * Test 3:
078 * subsume partially - map1 and map2.keySet()
079 */
080 assertTrue(map.subsumes(map2, map2.keySet()));
081 /**
082 * test 4:
083 * map2 SUBSUMES and map using the map2.keySet()
084 */
085 assertTrue(map2.subsumes(map, map2.keySet()));
086
087 /**
088 * test 5,6,7,8:
089 * test1,2,3,4 with NULL's in the map and
090 * not NULL's the map2 under the same key "3"
091 */
092 map.put("3", null);
093 map2.put("3", "not null");
094
095 assertTrue(!map.subsumes(map2));
096 assertTrue(!map2.subsumes(map));
097 assertTrue(!map.subsumes(map2, map2.keySet()));
098 assertTrue(!map2.subsumes(map, map2.keySet()));
099
100 /**
101 * Test 9,10,11,12 repeat the same test but with compatible (null) values
102 * under the same key "3"
103 */
104 map2.put("3", null);
105
106 assertTrue(map.subsumes(map2));
107 assertTrue(!map2.subsumes(map));
108 assertTrue(map.subsumes(map2, map2.keySet()));
109 assertTrue(map2.subsumes(map, map2.keySet()));
110
111 /**
112 * Test 13,14,15,16 repeat the same test but with null keys in the two of the maps
113 */
114 map.put(null, "5");
115 map2.put(null, "5");
116
117 assertTrue(map.subsumes(map2));
118 assertTrue(!map2.subsumes(map));
119 assertTrue(map.subsumes(map2, map2.keySet()));
120 assertTrue(map2.subsumes(map, map2.keySet()));
121 } // testSubsume()
122
123 /** Test suite routine for the test runner */
124 public static Test suite() {
125 return new TestSuite(TestFeatureMap.class);
126 } // suite
127
128 public static void main(String args[]){
129 TestFeatureMap app = new TestFeatureMap("TestFeatureMap");
130 try {
131 app.testPutAndGet();
132 app.testSubsume();
133 } catch (Exception e) {
134 e.printStackTrace (Err.getPrintWriter());
135 }
136 } // main
137 } // TestFeatureMap
|