1
15
16 package gate.util;
17
18 import junit.framework.*;
19
20
22 public class TestRBTreeMap extends TestCase
23 {
24
25 private static final boolean DEBUG = false;
26
27
28 public TestRBTreeMap(String name) { super(name); }
29
30
31 public void setUp() {
32 myTree=new RBTreeMap();
33 myTree.put(new Long(10),"Ten");
34 myTree.put(new Long(20),"Twenty");
35 myTree.put(new Long(30),"Thirty");
36 myTree.put(new Long(40),"Forty");
37 myTree.put(new Long(50),"Fifty");
38 }
40
41 public void testExact() {
42 Object result;
43 Long key;
44 String expected;
45
46 key=new Long(10);
48 expected="Ten";
49 result=myTree.get(key);
50 assertEquals(expected,result);
51
52 key=new Long(30);
54 expected="Thirty";
55 result=myTree.get(key);
56 assertEquals(expected,result);
57
58 key=new Long(50);
60 expected="Fifty";
61 result=myTree.get(key);
62 assertEquals(expected,result);
63
64 key=new Long(15);
66 result=myTree.get(key);
67 assertNull(result);
68
69 }
71 public void testClosestMatch(){
72 Object[] result;
73 Long key;
74 Object[] expected;
75
76 key=new Long(10);
78 expected=new Object[]{"Ten","Ten"};
79 result=myTree.getClosestMatch(key);
80 assertEquals("TestCM 1",expected[0],result[0]);
81 assertEquals("TestCM 2",expected[1],result[1]);
82
83 key=new Long(5);
85 expected=new Object[]{null,"Ten"};
86 result=myTree.getClosestMatch(key);
87 assertNull("TestCM 3",result[0]);
88 assertEquals("TestCM 4",expected[1],result[1]);
89
90 key=new Long(15);
92 expected=new Object[]{"Ten","Twenty"};
93 result=myTree.getClosestMatch(key);
94 assertEquals("TestCM 5",expected[0],result[0]);
95 assertEquals("TestCM 6",expected[1],result[1]);
96
97 key=new Long(55);
99 expected=new Object[]{"Fifty",null};
100 result=myTree.getClosestMatch(key);
101 assertEquals("TestCM 7",expected[0],result[0]);
102 assertNull("TestCM 8",result[1]);
103
104 myTree=new RBTreeMap();
106
107 key=new Long(15);
109 expected=new Object[]{null,null};
110 result=myTree.getClosestMatch(key);
111 assertNull("TestCM 9",result[0]);
112 assertNull("TestCM 10",result[1]);
113 }
114
115 public void testGetNextOf(){
116 Object result;
117 Long key;
118 String expected;
119
120 key=new Long(5);
122 expected="Ten";
123 result=myTree.getNextOf(key);
124 assertEquals(expected,result);
125
126 key=new Long(20);
128 expected="Twenty";
129 result=myTree.getNextOf(key);
130 assertEquals(expected,result);
131
132 key=new Long(15);
134 expected="Twenty";
135 result=myTree.getNextOf(key);
136 assertEquals(expected,result);
137
138 key=new Long(55);
140 result=myTree.getNextOf(key);
141 assertNull(result);
142
143 myTree=new RBTreeMap();
145 key=new Long(15);
146 result=myTree.getNextOf(key);
147 assertNull(result);
148 }
149
150
151
152 public static Test suite() {
153 return new TestSuite(TestRBTreeMap.class);
154 }
156
157 private RBTreeMap myTree;
158
159 }