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

Comparing jsr166/src/test/tck/ConcurrentSkipListSetTest.java (file contents):
Revision 1.2 by dl, Wed Apr 19 15:10:54 2006 UTC vs.
Revision 1.7 by jsr166, Sat Nov 21 02:07:26 2009 UTC

# Line 11 | Line 11 | import java.io.*;
11  
12   public class ConcurrentSkipListSetTest extends JSR166TestCase {
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run (suite());  
14 >        junit.textui.TestRunner.run (suite());
15      }
16      public static Test suite() {
17 <        return new TestSuite(ConcurrentSkipListSetTest.class);
17 >        return new TestSuite(ConcurrentSkipListSetTest.class);
18      }
19  
20 <    static class MyReverseComparator implements Comparator {
20 >    static class MyReverseComparator implements Comparator {
21          public int compare(Object x, Object y) {
22              int i = ((Integer)x).intValue();
23              int j = ((Integer)y).intValue();
# Line 34 | Line 34 | public class ConcurrentSkipListSetTest e
34      private ConcurrentSkipListSet populatedSet(int n) {
35          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
36          assertTrue(q.isEmpty());
37 <        for(int i = n-1; i >= 0; i-=2)
38 <            assertTrue(q.add(new Integer(i)));
39 <        for(int i = (n & 1); i < n; i+=2)
40 <            assertTrue(q.add(new Integer(i)));
37 >        for (int i = n-1; i >= 0; i-=2)
38 >            assertTrue(q.add(new Integer(i)));
39 >        for (int i = (n & 1); i < n; i+=2)
40 >            assertTrue(q.add(new Integer(i)));
41          assertFalse(q.isEmpty());
42 <        assertEquals(n, q.size());
42 >        assertEquals(n, q.size());
43          return q;
44      }
45  
# Line 54 | Line 54 | public class ConcurrentSkipListSetTest e
54          q.add(three);
55          q.add(four);
56          q.add(five);
57 <        assertEquals(5, q.size());
57 >        assertEquals(5, q.size());
58          return q;
59      }
60 <
60 >
61      /**
62       * A new set has unbounded capacity
63       */
# Line 168 | Line 168 | public class ConcurrentSkipListSetTest e
168       * add(null) throws NPE
169       */
170      public void testAddNull() {
171 <        try {
171 >        try {
172              ConcurrentSkipListSet q = new ConcurrentSkipListSet();
173              q.add(null);
174              shouldThrow();
175 <        } catch (NullPointerException success) { }  
175 >        } catch (NullPointerException success) { }
176      }
177  
178      /**
# Line 204 | Line 204 | public class ConcurrentSkipListSetTest e
204              q.add(new Object());
205              shouldThrow();
206          }
207 <        catch(ClassCastException success) {}
207 >        catch (ClassCastException success) {}
208      }
209  
210      /**
# Line 272 | Line 272 | public class ConcurrentSkipListSetTest e
272          for (int i = 0; i < SIZE; ++i) {
273              assertEquals(i, ((Integer)q.pollFirst()).intValue());
274          }
275 <        assertNull(q.pollFirst());
275 >        assertNull(q.pollFirst());
276      }
277  
278      /**
# Line 283 | Line 283 | public class ConcurrentSkipListSetTest e
283          for (int i = SIZE-1; i >= 0; --i) {
284              assertEquals(i, ((Integer)q.pollLast()).intValue());
285          }
286 <        assertNull(q.pollFirst());
286 >        assertNull(q.pollFirst());
287      }
288  
289  
# Line 301 | Line 301 | public class ConcurrentSkipListSetTest e
301          }
302          assertTrue(q.isEmpty());
303      }
304 <        
304 >
305      /**
306       * contains(x) reports true when elements added but not yet removed
307       */
# Line 377 | Line 377 | public class ConcurrentSkipListSetTest e
377          }
378      }
379  
380 <    
380 >
381  
382      /**
383       * lower returns preceding element
# Line 460 | Line 460 | public class ConcurrentSkipListSetTest e
460       */
461      public void testToArray() {
462          ConcurrentSkipListSet q = populatedSet(SIZE);
463 <        Object[] o = q.toArray();
463 >        Object[] o = q.toArray();
464          Arrays.sort(o);
465 <        for(int i = 0; i < o.length; i++)
466 <            assertEquals(o[i], q.pollFirst());
465 >        for (int i = 0; i < o.length; i++)
466 >            assertEquals(o[i], q.pollFirst());
467      }
468  
469      /**
# Line 471 | Line 471 | public class ConcurrentSkipListSetTest e
471       */
472      public void testToArray2() {
473          ConcurrentSkipListSet q = populatedSet(SIZE);
474 <        Integer[] ints = new Integer[SIZE];
475 <        ints = (Integer[])q.toArray(ints);
474 >        Integer[] ints = new Integer[SIZE];
475 >        ints = (Integer[])q.toArray(ints);
476          Arrays.sort(ints);
477 <        for(int i = 0; i < ints.length; i++)
477 >        for (int i = 0; i < ints.length; i++)
478              assertEquals(ints[i], q.pollFirst());
479      }
480 <    
480 >
481      /**
482       * iterator iterates through all elements
483       */
484      public void testIterator() {
485          ConcurrentSkipListSet q = populatedSet(SIZE);
486          int i = 0;
487 <        Iterator it = q.iterator();
488 <        while(it.hasNext()) {
487 >        Iterator it = q.iterator();
488 >        while (it.hasNext()) {
489              assertTrue(q.contains(it.next()));
490              ++i;
491          }
# Line 498 | Line 498 | public class ConcurrentSkipListSetTest e
498      public void testEmptyIterator() {
499          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
500          int i = 0;
501 <        Iterator it = q.iterator();
502 <        while(it.hasNext()) {
501 >        Iterator it = q.iterator();
502 >        while (it.hasNext()) {
503              assertTrue(q.contains(it.next()));
504              ++i;
505          }
# Line 535 | Line 535 | public class ConcurrentSkipListSetTest e
535          for (int i = 0; i < SIZE; ++i) {
536              assertTrue(s.indexOf(String.valueOf(i)) >= 0);
537          }
538 <    }        
538 >    }
539  
540      /**
541 <     * A deserialized serialized set has same elements
541 >     * A deserialized serialized set has same elements
542       */
543      public void testSerialization() {
544          ConcurrentSkipListSet q = populatedSet(SIZE);
# Line 552 | Line 552 | public class ConcurrentSkipListSetTest e
552              ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
553              ConcurrentSkipListSet r = (ConcurrentSkipListSet)in.readObject();
554              assertEquals(q.size(), r.size());
555 <            while (!q.isEmpty())
555 >            while (!q.isEmpty())
556                  assertEquals(q.pollFirst(), r.pollFirst());
557 <        } catch(Exception e){
557 >        } catch (Exception e) {
558              e.printStackTrace();
559              unexpectedException();
560          }
# Line 686 | Line 686 | public class ConcurrentSkipListSetTest e
686       * Subsets of subsets subdivide correctly
687       */
688      public void testRecursiveSubSets() {
689 <        int setSize = 1000;
690 <        Class cl = ConcurrentSkipListSet.class;
689 >        int setSize = 1000;
690 >        Class cl = ConcurrentSkipListSet.class;
691  
692          NavigableSet<Integer> set = newSet(cl);
693          bs = new BitSet(setSize);
# Line 700 | Line 700 | public class ConcurrentSkipListSetTest e
700          check(set,                 0, setSize - 1, true);
701          check(set.descendingSet(), 0, setSize - 1, false);
702  
703 <        bashSubSet(set.navigableSubSet(0, true, setSize, false),
703 >        bashSubSet(set.subSet(0, true, setSize, false),
704                     0, setSize - 1, true);
705      }
706  
707      static NavigableSet<Integer> newSet(Class cl) {
708          NavigableSet<Integer> result = null;
709 <        try {
709 >        try {
710              result = (NavigableSet<Integer>) cl.newInstance();
711 <        } catch(Exception e) {
711 >        } catch (Exception e) {
712              fail();
713 <        }
713 >        }
714          assertEquals(result.size(), 0);
715          assertFalse(result.iterator().hasNext());
716          return result;
# Line 733 | Line 733 | public class ConcurrentSkipListSetTest e
733          }
734  
735          // Remove a bunch of entries with iterator
736 <        for(Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
736 >        for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
737              if (rnd.nextBoolean()) {
738                  bs.clear(it.next());
739                  it.remove();
# Line 758 | Line 758 | public class ConcurrentSkipListSetTest e
758          }
759  
760          // Remove a bunch of entries with iterator
761 <        for(Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
761 >        for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
762              if (rnd.nextBoolean()) {
763                  bs.clear(it.next());
764                  it.remove();
# Line 774 | Line 774 | public class ConcurrentSkipListSetTest e
774                  try {
775                      set.add(element);
776                      fail();
777 <                } catch(IllegalArgumentException e) {
777 >                } catch (IllegalArgumentException e) {
778                      // expected
779                  }
780              }
# Line 807 | Line 807 | public class ConcurrentSkipListSetTest e
807  
808          // headSet - pick direction and endpoint inclusion randomly
809          boolean incl = rnd.nextBoolean();
810 <        NavigableSet<Integer> hm = set.navigableHeadSet(midPoint, incl);
810 >        NavigableSet<Integer> hm = set.headSet(midPoint, incl);
811          if (ascending) {
812              if (rnd.nextBoolean())
813                  bashSubSet(hm, min, midPoint - (incl ? 0 : 1), true);
# Line 824 | Line 824 | public class ConcurrentSkipListSetTest e
824  
825          // tailSet - pick direction and endpoint inclusion randomly
826          incl = rnd.nextBoolean();
827 <        NavigableSet<Integer> tm = set.navigableTailSet(midPoint,incl);
827 >        NavigableSet<Integer> tm = set.tailSet(midPoint,incl);
828          if (ascending) {
829              if (rnd.nextBoolean())
830                  bashSubSet(tm, midPoint + (incl ? 0 : 1), max, true);
# Line 849 | Line 849 | public class ConcurrentSkipListSetTest e
849          boolean lowIncl = rnd.nextBoolean();
850          boolean highIncl = rnd.nextBoolean();
851          if (ascending) {
852 <            NavigableSet<Integer> sm = set.navigableSubSet(
852 >            NavigableSet<Integer> sm = set.subSet(
853                  endpoints[0], lowIncl, endpoints[1], highIncl);
854              if (rnd.nextBoolean())
855                  bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1),
# Line 858 | Line 858 | public class ConcurrentSkipListSetTest e
858                  bashSubSet(sm.descendingSet(), endpoints[0] + (lowIncl ? 0 : 1),
859                             endpoints[1] - (highIncl ? 0 : 1), false);
860          } else {
861 <            NavigableSet<Integer> sm = set.navigableSubSet(
861 >            NavigableSet<Integer> sm = set.subSet(
862                  endpoints[1], highIncl, endpoints[0], lowIncl);
863              if (rnd.nextBoolean())
864                  bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1),
# Line 976 | Line 976 | public class ConcurrentSkipListSetTest e
976              try {
977                  set.first();
978                  fail();
979 <            } catch(NoSuchElementException e) {
979 >            } catch (NoSuchElementException e) {
980                  // expected
981              }
982              try {
983                  set.last();
984                  fail();
985 <            } catch(NoSuchElementException e) {
985 >            } catch (NoSuchElementException e) {
986                  // expected
987              }
988          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines