1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
64 |
|
} |
65 |
|
|
66 |
|
/** |
67 |
< |
* clear removes all pairs |
67 |
> |
* clear removes all pairs |
68 |
|
*/ |
69 |
|
public void testClear() { |
70 |
|
ConcurrentNavigableMap map = map5(); |
72 |
|
assertEquals(map.size(), 0); |
73 |
|
} |
74 |
|
|
75 |
– |
|
75 |
|
/** |
76 |
< |
* Maps with same contents are equal |
76 |
> |
* Maps with same contents are equal |
77 |
|
*/ |
78 |
|
public void testEquals() { |
79 |
|
ConcurrentNavigableMap map1 = map5(); |
86 |
|
} |
87 |
|
|
88 |
|
/** |
89 |
< |
* containsKey returns true for contained key |
89 |
> |
* containsKey returns true for contained key |
90 |
|
*/ |
91 |
|
public void testContainsKey() { |
92 |
|
ConcurrentNavigableMap map = map5(); |
95 |
|
} |
96 |
|
|
97 |
|
/** |
98 |
< |
* containsValue returns true for held values |
98 |
> |
* containsValue returns true for held values |
99 |
|
*/ |
100 |
|
public void testContainsValue() { |
101 |
|
ConcurrentNavigableMap map = map5(); |
104 |
|
} |
105 |
|
|
106 |
|
/** |
107 |
< |
* get returns the correct element at the given key, |
108 |
< |
* or null if not present |
107 |
> |
* get returns the correct element at the given key, |
108 |
> |
* or null if not present |
109 |
|
*/ |
110 |
|
public void testGet() { |
111 |
|
ConcurrentNavigableMap map = map5(); |
115 |
|
} |
116 |
|
|
117 |
|
/** |
118 |
< |
* isEmpty is true of empty map and false for non-empty |
118 |
> |
* isEmpty is true of empty map and false for non-empty |
119 |
|
*/ |
120 |
|
public void testIsEmpty() { |
121 |
|
ConcurrentNavigableMap empty = map0(); |
125 |
|
} |
126 |
|
|
127 |
|
/** |
128 |
< |
* firstKey returns first key |
128 |
> |
* firstKey returns first key |
129 |
|
*/ |
130 |
|
public void testFirstKey() { |
131 |
|
ConcurrentNavigableMap map = map5(); |
133 |
|
} |
134 |
|
|
135 |
|
/** |
136 |
< |
* lastKey returns last key |
136 |
> |
* lastKey returns last key |
137 |
|
*/ |
138 |
|
public void testLastKey() { |
139 |
|
ConcurrentNavigableMap map = map5(); |
140 |
|
assertEquals(five, map.lastKey()); |
141 |
|
} |
142 |
|
|
144 |
– |
|
143 |
|
/** |
144 |
< |
* keySet returns a Set containing all the keys |
144 |
> |
* keySet returns a Set containing all the keys |
145 |
|
*/ |
146 |
|
public void testKeySet() { |
147 |
|
ConcurrentNavigableMap map = map5(); |
155 |
|
} |
156 |
|
|
157 |
|
/** |
158 |
< |
* keySet is ordered |
158 |
> |
* keySet is ordered |
159 |
|
*/ |
160 |
|
public void testKeySetOrder() { |
161 |
|
ConcurrentNavigableMap map = map5(); |
185 |
|
} |
186 |
|
|
187 |
|
/** |
188 |
< |
* keySet.toArray returns contains all keys |
188 |
> |
* keySet.toArray returns contains all keys |
189 |
|
*/ |
190 |
|
public void testKeySetToArray() { |
191 |
|
ConcurrentNavigableMap map = map5(); |
198 |
|
} |
199 |
|
|
200 |
|
/** |
201 |
< |
* descendingkeySet.toArray returns contains all keys |
201 |
> |
* descendingkeySet.toArray returns contains all keys |
202 |
|
*/ |
203 |
|
public void testDescendingKeySetToArray() { |
204 |
|
ConcurrentNavigableMap map = map5(); |
211 |
|
} |
212 |
|
|
213 |
|
/** |
214 |
< |
* Values.toArray contains all values |
214 |
> |
* Values.toArray contains all values |
215 |
|
*/ |
216 |
|
public void testValuesToArray() { |
217 |
|
ConcurrentNavigableMap map = map5(); |
226 |
|
assertTrue(s.contains("E")); |
227 |
|
} |
228 |
|
|
231 |
– |
|
229 |
|
/** |
230 |
|
* entrySet contains all pairs |
231 |
|
*/ |
246 |
|
} |
247 |
|
|
248 |
|
/** |
249 |
< |
* putAll adds all key-value pairs from the given map |
249 |
> |
* putAll adds all key-value pairs from the given map |
250 |
|
*/ |
251 |
|
public void testPutAll() { |
252 |
|
ConcurrentNavigableMap empty = map0(); |
261 |
|
} |
262 |
|
|
263 |
|
/** |
264 |
< |
* putIfAbsent works when the given key is not present |
264 |
> |
* putIfAbsent works when the given key is not present |
265 |
|
*/ |
266 |
|
public void testPutIfAbsent() { |
267 |
|
ConcurrentNavigableMap map = map5(); |
270 |
|
} |
271 |
|
|
272 |
|
/** |
273 |
< |
* putIfAbsent does not add the pair if the key is already present |
273 |
> |
* putIfAbsent does not add the pair if the key is already present |
274 |
|
*/ |
275 |
|
public void testPutIfAbsent2() { |
276 |
|
ConcurrentNavigableMap map = map5(); |
278 |
|
} |
279 |
|
|
280 |
|
/** |
281 |
< |
* replace fails when the given key is not present |
281 |
> |
* replace fails when the given key is not present |
282 |
|
*/ |
283 |
|
public void testReplace() { |
284 |
|
ConcurrentNavigableMap map = map5(); |
287 |
|
} |
288 |
|
|
289 |
|
/** |
290 |
< |
* replace succeeds if the key is already present |
290 |
> |
* replace succeeds if the key is already present |
291 |
|
*/ |
292 |
|
public void testReplace2() { |
293 |
|
ConcurrentNavigableMap map = map5(); |
295 |
|
assertEquals("Z", map.get(one)); |
296 |
|
} |
297 |
|
|
301 |
– |
|
298 |
|
/** |
299 |
|
* replace value fails when the given key not mapped to expected value |
300 |
|
*/ |
315 |
|
assertEquals("Z", map.get(one)); |
316 |
|
} |
317 |
|
|
322 |
– |
|
318 |
|
/** |
319 |
< |
* remove removes the correct key-value pair from the map |
319 |
> |
* remove removes the correct key-value pair from the map |
320 |
|
*/ |
321 |
|
public void testRemove() { |
322 |
|
ConcurrentNavigableMap map = map5(); |
467 |
|
} |
468 |
|
|
469 |
|
/** |
470 |
< |
* size returns the correct values |
470 |
> |
* size returns the correct values |
471 |
|
*/ |
472 |
|
public void testSize() { |
473 |
|
ConcurrentNavigableMap map = map5(); |
483 |
|
ConcurrentNavigableMap map = map5(); |
484 |
|
String s = map.toString(); |
485 |
|
for (int i = 1; i <= 5; ++i) { |
486 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
486 |
> |
assertTrue(s.contains(String.valueOf(i))); |
487 |
|
} |
488 |
|
} |
489 |
|
|
522 |
|
} catch (NullPointerException success) {} |
523 |
|
} |
524 |
|
|
530 |
– |
|
525 |
|
/** |
526 |
|
* put(null,x) throws NPE |
527 |
|
*/ |
607 |
|
assertTrue(r.equals(q)); |
608 |
|
} |
609 |
|
|
616 |
– |
|
617 |
– |
|
610 |
|
/** |
611 |
|
* subMap returns map with keys in requested range |
612 |
|
*/ |
743 |
|
} |
744 |
|
|
745 |
|
/** |
746 |
< |
* clear removes all pairs |
746 |
> |
* clear removes all pairs |
747 |
|
*/ |
748 |
|
public void testDescendingClear() { |
749 |
|
ConcurrentNavigableMap map = dmap5(); |
751 |
|
assertEquals(map.size(), 0); |
752 |
|
} |
753 |
|
|
762 |
– |
|
754 |
|
/** |
755 |
< |
* Maps with same contents are equal |
755 |
> |
* Maps with same contents are equal |
756 |
|
*/ |
757 |
|
public void testDescendingEquals() { |
758 |
|
ConcurrentNavigableMap map1 = dmap5(); |
765 |
|
} |
766 |
|
|
767 |
|
/** |
768 |
< |
* containsKey returns true for contained key |
768 |
> |
* containsKey returns true for contained key |
769 |
|
*/ |
770 |
|
public void testDescendingContainsKey() { |
771 |
|
ConcurrentNavigableMap map = dmap5(); |
774 |
|
} |
775 |
|
|
776 |
|
/** |
777 |
< |
* containsValue returns true for held values |
777 |
> |
* containsValue returns true for held values |
778 |
|
*/ |
779 |
|
public void testDescendingContainsValue() { |
780 |
|
ConcurrentNavigableMap map = dmap5(); |
783 |
|
} |
784 |
|
|
785 |
|
/** |
786 |
< |
* get returns the correct element at the given key, |
787 |
< |
* or null if not present |
786 |
> |
* get returns the correct element at the given key, |
787 |
> |
* or null if not present |
788 |
|
*/ |
789 |
|
public void testDescendingGet() { |
790 |
|
ConcurrentNavigableMap map = dmap5(); |
794 |
|
} |
795 |
|
|
796 |
|
/** |
797 |
< |
* isEmpty is true of empty map and false for non-empty |
797 |
> |
* isEmpty is true of empty map and false for non-empty |
798 |
|
*/ |
799 |
|
public void testDescendingIsEmpty() { |
800 |
|
ConcurrentNavigableMap empty = dmap0(); |
804 |
|
} |
805 |
|
|
806 |
|
/** |
807 |
< |
* firstKey returns first key |
807 |
> |
* firstKey returns first key |
808 |
|
*/ |
809 |
|
public void testDescendingFirstKey() { |
810 |
|
ConcurrentNavigableMap map = dmap5(); |
812 |
|
} |
813 |
|
|
814 |
|
/** |
815 |
< |
* lastKey returns last key |
815 |
> |
* lastKey returns last key |
816 |
|
*/ |
817 |
|
public void testDescendingLastKey() { |
818 |
|
ConcurrentNavigableMap map = dmap5(); |
819 |
|
assertEquals(m5, map.lastKey()); |
820 |
|
} |
821 |
|
|
831 |
– |
|
822 |
|
/** |
823 |
< |
* keySet returns a Set containing all the keys |
823 |
> |
* keySet returns a Set containing all the keys |
824 |
|
*/ |
825 |
|
public void testDescendingKeySet() { |
826 |
|
ConcurrentNavigableMap map = dmap5(); |
834 |
|
} |
835 |
|
|
836 |
|
/** |
837 |
< |
* keySet is ordered |
837 |
> |
* keySet is ordered |
838 |
|
*/ |
839 |
|
public void testDescendingKeySetOrder() { |
840 |
|
ConcurrentNavigableMap map = dmap5(); |
864 |
|
} |
865 |
|
|
866 |
|
/** |
867 |
< |
* keySet.toArray returns contains all keys |
867 |
> |
* keySet.toArray returns contains all keys |
868 |
|
*/ |
869 |
|
public void testDescendingAscendingKeySetToArray() { |
870 |
|
ConcurrentNavigableMap map = dmap5(); |
877 |
|
} |
878 |
|
|
879 |
|
/** |
880 |
< |
* descendingkeySet.toArray returns contains all keys |
880 |
> |
* descendingkeySet.toArray returns contains all keys |
881 |
|
*/ |
882 |
|
public void testDescendingDescendingKeySetToArray() { |
883 |
|
ConcurrentNavigableMap map = dmap5(); |
890 |
|
} |
891 |
|
|
892 |
|
/** |
893 |
< |
* Values.toArray contains all values |
893 |
> |
* Values.toArray contains all values |
894 |
|
*/ |
895 |
|
public void testDescendingValuesToArray() { |
896 |
|
ConcurrentNavigableMap map = dmap5(); |
905 |
|
assertTrue(s.contains("E")); |
906 |
|
} |
907 |
|
|
918 |
– |
|
908 |
|
/** |
909 |
|
* entrySet contains all pairs |
910 |
|
*/ |
925 |
|
} |
926 |
|
|
927 |
|
/** |
928 |
< |
* putAll adds all key-value pairs from the given map |
928 |
> |
* putAll adds all key-value pairs from the given map |
929 |
|
*/ |
930 |
|
public void testDescendingPutAll() { |
931 |
|
ConcurrentNavigableMap empty = dmap0(); |
940 |
|
} |
941 |
|
|
942 |
|
/** |
943 |
< |
* putIfAbsent works when the given key is not present |
943 |
> |
* putIfAbsent works when the given key is not present |
944 |
|
*/ |
945 |
|
public void testDescendingPutIfAbsent() { |
946 |
|
ConcurrentNavigableMap map = dmap5(); |
949 |
|
} |
950 |
|
|
951 |
|
/** |
952 |
< |
* putIfAbsent does not add the pair if the key is already present |
952 |
> |
* putIfAbsent does not add the pair if the key is already present |
953 |
|
*/ |
954 |
|
public void testDescendingPutIfAbsent2() { |
955 |
|
ConcurrentNavigableMap map = dmap5(); |
957 |
|
} |
958 |
|
|
959 |
|
/** |
960 |
< |
* replace fails when the given key is not present |
960 |
> |
* replace fails when the given key is not present |
961 |
|
*/ |
962 |
|
public void testDescendingReplace() { |
963 |
|
ConcurrentNavigableMap map = dmap5(); |
966 |
|
} |
967 |
|
|
968 |
|
/** |
969 |
< |
* replace succeeds if the key is already present |
969 |
> |
* replace succeeds if the key is already present |
970 |
|
*/ |
971 |
|
public void testDescendingReplace2() { |
972 |
|
ConcurrentNavigableMap map = dmap5(); |
974 |
|
assertEquals("Z", map.get(m1)); |
975 |
|
} |
976 |
|
|
988 |
– |
|
977 |
|
/** |
978 |
|
* replace value fails when the given key not mapped to expected value |
979 |
|
*/ |
994 |
|
assertEquals("Z", map.get(m1)); |
995 |
|
} |
996 |
|
|
1009 |
– |
|
997 |
|
/** |
998 |
< |
* remove removes the correct key-value pair from the map |
998 |
> |
* remove removes the correct key-value pair from the map |
999 |
|
*/ |
1000 |
|
public void testDescendingRemove() { |
1001 |
|
ConcurrentNavigableMap map = dmap5(); |
1146 |
|
} |
1147 |
|
|
1148 |
|
/** |
1149 |
< |
* size returns the correct values |
1149 |
> |
* size returns the correct values |
1150 |
|
*/ |
1151 |
|
public void testDescendingSize() { |
1152 |
|
ConcurrentNavigableMap map = dmap5(); |
1162 |
|
ConcurrentNavigableMap map = dmap5(); |
1163 |
|
String s = map.toString(); |
1164 |
|
for (int i = 1; i <= 5; ++i) { |
1165 |
< |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
1165 |
> |
assertTrue(s.contains(String.valueOf(i))); |
1166 |
|
} |
1167 |
|
} |
1168 |
|
|
1201 |
|
} catch (NullPointerException success) {} |
1202 |
|
} |
1203 |
|
|
1217 |
– |
|
1204 |
|
/** |
1205 |
|
* put(null,x) throws NPE |
1206 |
|
*/ |
1286 |
|
assertTrue(r.equals(q)); |
1287 |
|
} |
1288 |
|
|
1303 |
– |
|
1289 |
|
/** |
1290 |
|
* subMap returns map with keys in requested range |
1291 |
|
*/ |