ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ConcurrentSkipListMapTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ConcurrentSkipListMapTest.java (file contents):
Revision 1.14 by jsr166, Sat Nov 21 17:38:05 2009 UTC vs.
Revision 1.29 by jsr166, Tue Feb 21 01:54:03 2012 UTC

# Line 1 | Line 1
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.*;
8   import java.util.*;
9 < import java.util.concurrent.*;
10 < import java.io.*;
9 > import java.util.concurrent.ConcurrentSkipListMap;
10  
11   public class ConcurrentSkipListMapTest extends JSR166TestCase {
12      public static void main(String[] args) {
13 <        junit.textui.TestRunner.run (suite());
13 >        junit.textui.TestRunner.run(suite());
14      }
15      public static Test suite() {
16          return new TestSuite(ConcurrentSkipListMapTest.class);
17      }
18  
19      /**
20 <     * Create a map from Integers 1-5 to Strings "A"-"E".
20 >     * Creates a map from Integers 1-5 to Strings "A"-"E".
21       */
22      private static ConcurrentSkipListMap map5() {
23          ConcurrentSkipListMap map = new ConcurrentSkipListMap();
# Line 34 | Line 33 | public class ConcurrentSkipListMapTest e
33      }
34  
35      /**
36 <     *  clear removes all pairs
36 >     * clear removes all pairs
37       */
38      public void testClear() {
39          ConcurrentSkipListMap map = map5();
40          map.clear();
41 <        assertEquals(map.size(), 0);
41 >        assertEquals(0, map.size());
42      }
43  
44      /**
# Line 52 | Line 51 | public class ConcurrentSkipListMapTest e
51      }
52  
53      /**
54 <     *  Maps with same contents are equal
54 >     * Maps with same contents are equal
55       */
56      public void testEquals() {
57          ConcurrentSkipListMap map1 = map5();
# Line 65 | Line 64 | public class ConcurrentSkipListMapTest e
64      }
65  
66      /**
67 <     *  containsKey returns true for contained key
67 >     * containsKey returns true for contained key
68       */
69      public void testContainsKey() {
70          ConcurrentSkipListMap map = map5();
# Line 74 | Line 73 | public class ConcurrentSkipListMapTest e
73      }
74  
75      /**
76 <     *  containsValue returns true for held values
76 >     * containsValue returns true for held values
77       */
78      public void testContainsValue() {
79          ConcurrentSkipListMap map = map5();
# Line 83 | Line 82 | public class ConcurrentSkipListMapTest e
82      }
83  
84      /**
85 <     *  get returns the correct element at the given key,
86 <     *  or null if not present
85 >     * get returns the correct element at the given key,
86 >     * or null if not present
87       */
88      public void testGet() {
89          ConcurrentSkipListMap map = map5();
# Line 94 | Line 93 | public class ConcurrentSkipListMapTest e
93      }
94  
95      /**
96 <     *  isEmpty is true of empty map and false for non-empty
96 >     * isEmpty is true of empty map and false for non-empty
97       */
98      public void testIsEmpty() {
99          ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
# Line 104 | Line 103 | public class ConcurrentSkipListMapTest e
103      }
104  
105      /**
106 <     *   firstKey returns first key
106 >     * firstKey returns first key
107       */
108      public void testFirstKey() {
109          ConcurrentSkipListMap map = map5();
# Line 112 | Line 111 | public class ConcurrentSkipListMapTest e
111      }
112  
113      /**
114 <     *   lastKey returns last key
114 >     * lastKey returns last key
115       */
116      public void testLastKey() {
117          ConcurrentSkipListMap map = map5();
118          assertEquals(five, map.lastKey());
119      }
120  
122
121      /**
122 <     *  keySet.toArray returns contains all keys
122 >     * keySet.toArray returns contains all keys
123       */
124      public void testKeySetToArray() {
125          ConcurrentSkipListMap map = map5();
# Line 134 | Line 132 | public class ConcurrentSkipListMapTest e
132      }
133  
134      /**
135 <     *  descendingkeySet.toArray returns contains all keys
135 >     * descendingkeySet.toArray returns contains all keys
136       */
137      public void testDescendingKeySetToArray() {
138          ConcurrentSkipListMap map = map5();
# Line 147 | Line 145 | public class ConcurrentSkipListMapTest e
145      }
146  
147      /**
148 <     *   keySet returns a Set containing all the keys
148 >     * keySet returns a Set containing all the keys
149       */
150      public void testKeySet() {
151          ConcurrentSkipListMap map = map5();
# Line 161 | Line 159 | public class ConcurrentSkipListMapTest e
159      }
160  
161      /**
162 <     *   keySet is ordered
162 >     * keySet is ordered
163       */
164      public void testKeySetOrder() {
165          ConcurrentSkipListMap map = map5();
# Line 176 | Line 174 | public class ConcurrentSkipListMapTest e
174              last = k;
175              ++count;
176          }
177 <        assertEquals(count ,5);
177 >        assertEquals(5, count);
178      }
179  
180      /**
# Line 195 | Line 193 | public class ConcurrentSkipListMapTest e
193              last = k;
194              ++count;
195          }
196 <        assertEquals(count ,5);
196 >        assertEquals(5, count);
197      }
198  
199      /**
200 <     *   descendingKeySet is ordered
200 >     * descendingKeySet is ordered
201       */
202      public void testDescendingKeySetOrder() {
203          ConcurrentSkipListMap map = map5();
# Line 214 | Line 212 | public class ConcurrentSkipListMapTest e
212              last = k;
213              ++count;
214          }
215 <        assertEquals(count, 5);
215 >        assertEquals(5, count);
216      }
217  
218      /**
219 <     *  descending iterator of descendingKeySet is ordered
219 >     * descending iterator of descendingKeySet is ordered
220       */
221      public void testDescendingKeySetDescendingIteratorOrder() {
222          ConcurrentSkipListMap map = map5();
# Line 233 | Line 231 | public class ConcurrentSkipListMapTest e
231              last = k;
232              ++count;
233          }
234 <        assertEquals(count, 5);
234 >        assertEquals(5, count);
235      }
236  
237      /**
238 <     *  Values.toArray contains all values
238 >     * Values.toArray contains all values
239       */
240      public void testValuesToArray() {
241          ConcurrentSkipListMap map = map5();
# Line 305 | Line 303 | public class ConcurrentSkipListMapTest e
303      }
304  
305      /**
306 <     *  entrySet.toArray contains all entries
306 >     * entrySet.toArray contains all entries
307       */
308      public void testEntrySetToArray() {
309          ConcurrentSkipListMap map = map5();
# Line 319 | Line 317 | public class ConcurrentSkipListMapTest e
317      }
318  
319      /**
320 <     *  descendingEntrySet.toArray contains all entries
320 >     * descendingEntrySet.toArray contains all entries
321       */
322      public void testDescendingEntrySetToArray() {
323          ConcurrentSkipListMap map = map5();
# Line 333 | Line 331 | public class ConcurrentSkipListMapTest e
331      }
332  
333      /**
334 <     *   putAll  adds all key-value pairs from the given map
334 >     * putAll adds all key-value pairs from the given map
335       */
336      public void testPutAll() {
337          ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
# Line 348 | Line 346 | public class ConcurrentSkipListMapTest e
346      }
347  
348      /**
349 <     *   putIfAbsent works when the given key is not present
349 >     * putIfAbsent works when the given key is not present
350       */
351      public void testPutIfAbsent() {
352          ConcurrentSkipListMap map = map5();
# Line 357 | Line 355 | public class ConcurrentSkipListMapTest e
355      }
356  
357      /**
358 <     *   putIfAbsent does not add the pair if the key is already present
358 >     * putIfAbsent does not add the pair if the key is already present
359       */
360      public void testPutIfAbsent2() {
361          ConcurrentSkipListMap map = map5();
# Line 365 | Line 363 | public class ConcurrentSkipListMapTest e
363      }
364  
365      /**
366 <     *   replace fails when the given key is not present
366 >     * replace fails when the given key is not present
367       */
368      public void testReplace() {
369          ConcurrentSkipListMap map = map5();
# Line 374 | Line 372 | public class ConcurrentSkipListMapTest e
372      }
373  
374      /**
375 <     *   replace succeeds if the key is already present
375 >     * replace succeeds if the key is already present
376       */
377      public void testReplace2() {
378          ConcurrentSkipListMap map = map5();
# Line 382 | Line 380 | public class ConcurrentSkipListMapTest e
380          assertEquals("Z", map.get(one));
381      }
382  
385
383      /**
384       * replace value fails when the given key not mapped to expected value
385       */
# Line 403 | Line 400 | public class ConcurrentSkipListMapTest e
400          assertEquals("Z", map.get(one));
401      }
402  
406
403      /**
404 <     *   remove removes the correct key-value pair from the map
404 >     * remove removes the correct key-value pair from the map
405       */
406      public void testRemove() {
407          ConcurrentSkipListMap map = map5();
# Line 427 | Line 423 | public class ConcurrentSkipListMapTest e
423          map.remove(four, "A");
424          assertEquals(4, map.size());
425          assertTrue(map.containsKey(four));
430
426      }
427  
428      /**
# Line 446 | Line 441 | public class ConcurrentSkipListMapTest e
441  
442          Map.Entry e4 = map.lowerEntry(zero);
443          assertNull(e4);
449
444      }
445  
446      /**
# Line 465 | Line 459 | public class ConcurrentSkipListMapTest e
459  
460          Map.Entry e4 = map.higherEntry(six);
461          assertNull(e4);
468
462      }
463  
464      /**
# Line 484 | Line 477 | public class ConcurrentSkipListMapTest e
477  
478          Map.Entry e4 = map.floorEntry(zero);
479          assertNull(e4);
487
480      }
481  
482      /**
# Line 503 | Line 495 | public class ConcurrentSkipListMapTest e
495  
496          Map.Entry e4 = map.ceilingEntry(six);
497          assertNull(e4);
506
498      }
499  
500      /**
501       * lowerEntry, higherEntry, ceilingEntry, and floorEntry return
502 <     * imutable entries
502 >     * immutable entries
503       */
504 <    public void testEntryImmutablity() {
504 >    public void testEntryImmutability() {
505          ConcurrentSkipListMap map = map5();
506          Map.Entry e = map.lowerEntry(three);
507          assertEquals(two, e.getKey());
# Line 538 | Line 529 | public class ConcurrentSkipListMapTest e
529          } catch (UnsupportedOperationException success) {}
530      }
531  
541
542
532      /**
533       * lowerKey returns preceding element
534       */
# Line 556 | Line 545 | public class ConcurrentSkipListMapTest e
545  
546          Object e4 = q.lowerKey(zero);
547          assertNull(e4);
559
548      }
549  
550      /**
# Line 575 | Line 563 | public class ConcurrentSkipListMapTest e
563  
564          Object e4 = q.higherKey(six);
565          assertNull(e4);
578
566      }
567  
568      /**
# Line 594 | Line 581 | public class ConcurrentSkipListMapTest e
581  
582          Object e4 = q.floorKey(zero);
583          assertNull(e4);
597
584      }
585  
586      /**
# Line 613 | Line 599 | public class ConcurrentSkipListMapTest e
599  
600          Object e4 = q.ceilingKey(six);
601          assertNull(e4);
616
602      }
603  
604      /**
# Line 671 | Line 656 | public class ConcurrentSkipListMapTest e
656      }
657  
658      /**
659 <     *   size returns the correct values
659 >     * size returns the correct values
660       */
661      public void testSize() {
662          ConcurrentSkipListMap map = map5();
# Line 687 | Line 672 | public class ConcurrentSkipListMapTest e
672          ConcurrentSkipListMap map = map5();
673          String s = map.toString();
674          for (int i = 1; i <= 5; ++i) {
675 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
675 >            assertTrue(s.contains(String.valueOf(i)));
676          }
677      }
678  
# Line 726 | Line 711 | public class ConcurrentSkipListMapTest e
711          } catch (NullPointerException success) {}
712      }
713  
729
714      /**
715       * put(null,x) throws NPE
716       */
# Line 808 | Line 792 | public class ConcurrentSkipListMapTest e
792       * A deserialized map equals original
793       */
794      public void testSerialization() throws Exception {
795 <        ConcurrentSkipListMap q = map5();
795 >        NavigableMap x = map5();
796 >        NavigableMap y = serialClone(x);
797  
798 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
799 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
800 <        out.writeObject(q);
801 <        out.close();
802 <
818 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
819 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
820 <        ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject();
821 <        assertEquals(q.size(), r.size());
822 <        assertTrue(q.equals(r));
823 <        assertTrue(r.equals(q));
798 >        assertTrue(x != y);
799 >        assertEquals(x.size(), y.size());
800 >        assertEquals(x.toString(), y.toString());
801 >        assertEquals(x, y);
802 >        assertEquals(y, x);
803      }
804  
826
827
805      /**
806       * subMap returns map with keys in requested range
807       */
# Line 861 | Line 838 | public class ConcurrentSkipListMapTest e
838          assertEquals(1, sm.size());
839          assertEquals(three, sm.firstKey());
840          assertEquals(three, sm.lastKey());
841 <        assertTrue(sm.remove(three) != null);
841 >        assertEquals("C", sm.remove(three));
842          assertTrue(sm.isEmpty());
843          assertEquals(3, map.size());
844      }
# Line 894 | Line 871 | public class ConcurrentSkipListMapTest e
871          assertEquals(4, map.size());
872          assertEquals(0, sm.size());
873          assertTrue(sm.isEmpty());
874 <        assertTrue(sm.remove(three) == null);
874 >        assertSame(sm.remove(three), null);
875          assertEquals(4, map.size());
876      }
877  
# Line 976 | Line 953 | public class ConcurrentSkipListMapTest e
953          NavigableMap ssm = sm.tailMap(four, true);
954          assertEquals(four, ssm.firstKey());
955          assertEquals(five, ssm.lastKey());
956 <        assertTrue(ssm.remove(four) != null);
956 >        assertEquals("D", ssm.remove(four));
957          assertEquals(1, ssm.size());
958          assertEquals(3, sm.size());
959          assertEquals(4, map.size());
# Line 989 | Line 966 | public class ConcurrentSkipListMapTest e
966       * Submaps of submaps subdivide correctly
967       */
968      public void testRecursiveSubMaps() throws Exception {
969 <        int mapSize = 1000;
969 >        int mapSize = expensiveTests ? 1000 : 100;
970          Class cl = ConcurrentSkipListMap.class;
971          NavigableMap<Integer, Integer> map = newMap(cl);
972          bs = new BitSet(mapSize);
# Line 1009 | Line 986 | public class ConcurrentSkipListMapTest e
986      static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
987          NavigableMap<Integer, Integer> result =
988              (NavigableMap<Integer, Integer>) cl.newInstance();
989 <        assertEquals(result.size(), 0);
989 >        assertEquals(0, result.size());
990          assertFalse(result.keySet().iterator().hasNext());
991          return result;
992      }
# Line 1170 | Line 1147 | public class ConcurrentSkipListMapTest e
1147       */
1148      void check(NavigableMap<Integer, Integer> map,
1149                        final int min, final int max, final boolean ascending) {
1150 <       class ReferenceSet {
1150 >        class ReferenceSet {
1151              int lower(int key) {
1152                  return ascending ? lowerAscending(key) : higherAscending(key);
1153              }
# Line 1201 | Line 1178 | public class ConcurrentSkipListMapTest e
1178                  // BitSet should support this! Test would run much faster
1179                  while (key >= min) {
1180                      if (bs.get(key))
1181 <                        return(key);
1181 >                        return key;
1182                      key--;
1183                  }
1184                  return -1;
# Line 1236 | Line 1213 | public class ConcurrentSkipListMapTest e
1213              if (bsContainsI)
1214                  size++;
1215          }
1216 <        assertEquals(map.size(), size);
1216 >        assertEquals(size, map.size());
1217  
1218          // Test contents using contains keySet iterator
1219          int size2 = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines