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.9 by jsr166, Sat Nov 21 10:29:50 2009 UTC vs.
Revision 1.18 by jsr166, Fri Nov 5 00:17:22 2010 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);
# Line 19 | Line 19 | public class ConcurrentSkipListSetTest e
19  
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();
24 <            if (i < j) return 1;
25 <            if (i > j) return -1;
26 <            return 0;
22 >            return ((Comparable)y).compareTo(x);
23          }
24      }
25  
# Line 31 | Line 27 | public class ConcurrentSkipListSetTest e
27       * Create a set of given size containing consecutive
28       * Integers 0 ... n.
29       */
30 <    private ConcurrentSkipListSet populatedSet(int n) {
31 <        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
30 >    private ConcurrentSkipListSet<Integer> populatedSet(int n) {
31 >        ConcurrentSkipListSet<Integer> q =
32 >            new ConcurrentSkipListSet<Integer>();
33          assertTrue(q.isEmpty());
34          for (int i = n-1; i >= 0; i-=2)
35              assertTrue(q.add(new Integer(i)));
# Line 207 | Line 204 | public class ConcurrentSkipListSetTest e
204              shouldThrow();
205          } catch (NullPointerException success) {}
206      }
207 +
208      /**
209       * addAll of a collection with null elements throws NPE
210       */
# Line 218 | Line 216 | public class ConcurrentSkipListSetTest e
216              shouldThrow();
217          } catch (NullPointerException success) {}
218      }
219 +
220      /**
221       * addAll of a collection with any null elements throws NPE after
222       * possibly adding some elements
# Line 245 | Line 244 | public class ConcurrentSkipListSetTest e
244          assertFalse(q.addAll(Arrays.asList(empty)));
245          assertTrue(q.addAll(Arrays.asList(ints)));
246          for (int i = 0; i < SIZE; ++i)
247 <            assertEquals(new Integer(i), q.pollFirst());
247 >            assertEquals(i, q.pollFirst());
248      }
249  
250      /**
# Line 254 | Line 253 | public class ConcurrentSkipListSetTest e
253      public void testPollFirst() {
254          ConcurrentSkipListSet q = populatedSet(SIZE);
255          for (int i = 0; i < SIZE; ++i) {
256 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
256 >            assertEquals(i, q.pollFirst());
257          }
258          assertNull(q.pollFirst());
259      }
# Line 265 | Line 264 | public class ConcurrentSkipListSetTest e
264      public void testPollLast() {
265          ConcurrentSkipListSet q = populatedSet(SIZE);
266          for (int i = SIZE-1; i >= 0; --i) {
267 <            assertEquals(i, ((Integer)q.pollLast()).intValue());
267 >            assertEquals(i, q.pollLast());
268          }
269          assertNull(q.pollFirst());
270      }
# Line 379 | Line 378 | public class ConcurrentSkipListSetTest e
378  
379          Object e4 = q.lower(zero);
380          assertNull(e4);
382
381      }
382  
383      /**
# Line 398 | Line 396 | public class ConcurrentSkipListSetTest e
396  
397          Object e4 = q.higher(six);
398          assertNull(e4);
401
399      }
400  
401      /**
# Line 417 | Line 414 | public class ConcurrentSkipListSetTest e
414  
415          Object e4 = q.floor(zero);
416          assertNull(e4);
420
417      }
418  
419      /**
# Line 436 | Line 432 | public class ConcurrentSkipListSetTest e
432  
433          Object e4 = q.ceiling(six);
434          assertNull(e4);
439
435      }
436  
437      /**
438 <     * toArray contains all elements
438 >     * toArray contains all elements in sorted order
439       */
440      public void testToArray() {
441          ConcurrentSkipListSet q = populatedSet(SIZE);
442          Object[] o = q.toArray();
448        Arrays.sort(o);
443          for (int i = 0; i < o.length; i++)
444 <            assertEquals(o[i], q.pollFirst());
444 >            assertSame(o[i], q.pollFirst());
445      }
446  
447      /**
448 <     * toArray(a) contains all elements
448 >     * toArray(a) contains all elements in sorted order
449       */
450      public void testToArray2() {
451 <        ConcurrentSkipListSet q = populatedSet(SIZE);
451 >        ConcurrentSkipListSet<Integer> q = populatedSet(SIZE);
452          Integer[] ints = new Integer[SIZE];
453 <        ints = (Integer[])q.toArray(ints);
454 <        Arrays.sort(ints);
453 >        Integer[] array = q.toArray(ints);
454 >        assertSame(ints, array);
455          for (int i = 0; i < ints.length; i++)
456 <            assertEquals(ints[i], q.pollFirst());
456 >            assertSame(ints[i], q.pollFirst());
457      }
458  
459      /**
# Line 493 | Line 487 | public class ConcurrentSkipListSetTest e
487      /**
488       * iterator.remove removes current element
489       */
490 <    public void testIteratorRemove () {
490 >    public void testIteratorRemove() {
491          final ConcurrentSkipListSet q = new ConcurrentSkipListSet();
492          q.add(new Integer(2));
493          q.add(new Integer(1));
# Line 664 | Line 658 | public class ConcurrentSkipListSetTest e
658      /**
659       * Subsets of subsets subdivide correctly
660       */
661 <    public void testRecursiveSubSets() {
662 <        int setSize = 1000;
661 >    public void testRecursiveSubSets() throws Exception {
662 >        int setSize = expensiveTests ? 1000 : 100;
663          Class cl = ConcurrentSkipListSet.class;
664  
665          NavigableSet<Integer> set = newSet(cl);
# Line 683 | Line 677 | public class ConcurrentSkipListSetTest e
677                     0, setSize - 1, true);
678      }
679  
680 <    static NavigableSet<Integer> newSet(Class cl) {
681 <        NavigableSet<Integer> result = null;
688 <        try {
689 <            result = (NavigableSet<Integer>) cl.newInstance();
690 <        } catch (Exception e) {
691 <            fail();
692 <        }
680 >    static NavigableSet<Integer> newSet(Class cl) throws Exception {
681 >        NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance();
682          assertEquals(result.size(), 0);
683          assertFalse(result.iterator().hasNext());
684          return result;
# Line 752 | Line 741 | public class ConcurrentSkipListSetTest e
741              } else {
742                  try {
743                      set.add(element);
744 <                    fail();
745 <                } catch (IllegalArgumentException e) {
757 <                    // expected
758 <                }
744 >                    shouldThrow();
745 >                } catch (IllegalArgumentException success) {}
746              }
747          }
748      }
# Line 888 | Line 875 | public class ConcurrentSkipListSetTest e
875                  // BitSet should support this! Test would run much faster
876                  while (element >= min) {
877                      if (bs.get(element))
878 <                        return(element);
878 >                        return element;
879                      element--;
880                  }
881                  return -1;
# Line 954 | Line 941 | public class ConcurrentSkipListSetTest e
941              assertEq(rs.last(),  -1);
942              try {
943                  set.first();
944 <                fail();
945 <            } catch (NoSuchElementException e) {
959 <                // expected
960 <            }
944 >                shouldThrow();
945 >            } catch (NoSuchElementException success) {}
946              try {
947                  set.last();
948 <                fail();
949 <            } catch (NoSuchElementException e) {
965 <                // expected
966 <            }
948 >                shouldThrow();
949 >            } catch (NoSuchElementException success) {}
950          }
951      }
952  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines