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.17 by jsr166, Thu Nov 4 01:04:54 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 207 | Line 203 | public class ConcurrentSkipListSetTest e
203              shouldThrow();
204          } catch (NullPointerException success) {}
205      }
206 +
207      /**
208       * addAll of a collection with null elements throws NPE
209       */
# Line 218 | Line 215 | public class ConcurrentSkipListSetTest e
215              shouldThrow();
216          } catch (NullPointerException success) {}
217      }
218 +
219      /**
220       * addAll of a collection with any null elements throws NPE after
221       * possibly adding some elements
# Line 245 | Line 243 | public class ConcurrentSkipListSetTest e
243          assertFalse(q.addAll(Arrays.asList(empty)));
244          assertTrue(q.addAll(Arrays.asList(ints)));
245          for (int i = 0; i < SIZE; ++i)
246 <            assertEquals(new Integer(i), q.pollFirst());
246 >            assertEquals(i, q.pollFirst());
247      }
248  
249      /**
# Line 254 | Line 252 | public class ConcurrentSkipListSetTest e
252      public void testPollFirst() {
253          ConcurrentSkipListSet q = populatedSet(SIZE);
254          for (int i = 0; i < SIZE; ++i) {
255 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
255 >            assertEquals(i, q.pollFirst());
256          }
257          assertNull(q.pollFirst());
258      }
# Line 265 | Line 263 | public class ConcurrentSkipListSetTest e
263      public void testPollLast() {
264          ConcurrentSkipListSet q = populatedSet(SIZE);
265          for (int i = SIZE-1; i >= 0; --i) {
266 <            assertEquals(i, ((Integer)q.pollLast()).intValue());
266 >            assertEquals(i, q.pollLast());
267          }
268          assertNull(q.pollFirst());
269      }
# Line 379 | Line 377 | public class ConcurrentSkipListSetTest e
377  
378          Object e4 = q.lower(zero);
379          assertNull(e4);
382
380      }
381  
382      /**
# Line 398 | Line 395 | public class ConcurrentSkipListSetTest e
395  
396          Object e4 = q.higher(six);
397          assertNull(e4);
401
398      }
399  
400      /**
# Line 417 | Line 413 | public class ConcurrentSkipListSetTest e
413  
414          Object e4 = q.floor(zero);
415          assertNull(e4);
420
416      }
417  
418      /**
# Line 436 | Line 431 | public class ConcurrentSkipListSetTest e
431  
432          Object e4 = q.ceiling(six);
433          assertNull(e4);
439
434      }
435  
436      /**
437 <     * toArray contains all elements
437 >     * toArray contains all elements in sorted order
438       */
439      public void testToArray() {
440          ConcurrentSkipListSet q = populatedSet(SIZE);
441          Object[] o = q.toArray();
448        Arrays.sort(o);
442          for (int i = 0; i < o.length; i++)
443 <            assertEquals(o[i], q.pollFirst());
443 >            assertSame(o[i], q.pollFirst());
444      }
445  
446      /**
447 <     * toArray(a) contains all elements
447 >     * toArray(a) contains all elements in sorted order
448       */
449      public void testToArray2() {
450          ConcurrentSkipListSet q = populatedSet(SIZE);
451          Integer[] ints = new Integer[SIZE];
452 <        ints = (Integer[])q.toArray(ints);
460 <        Arrays.sort(ints);
452 >        assertSame(ints, q.toArray(ints));
453          for (int i = 0; i < ints.length; i++)
454 <            assertEquals(ints[i], q.pollFirst());
454 >            assertSame(ints[i], q.pollFirst());
455      }
456  
457      /**
# Line 493 | Line 485 | public class ConcurrentSkipListSetTest e
485      /**
486       * iterator.remove removes current element
487       */
488 <    public void testIteratorRemove () {
488 >    public void testIteratorRemove() {
489          final ConcurrentSkipListSet q = new ConcurrentSkipListSet();
490          q.add(new Integer(2));
491          q.add(new Integer(1));
# Line 664 | Line 656 | public class ConcurrentSkipListSetTest e
656      /**
657       * Subsets of subsets subdivide correctly
658       */
659 <    public void testRecursiveSubSets() {
660 <        int setSize = 1000;
659 >    public void testRecursiveSubSets() throws Exception {
660 >        int setSize = expensiveTests ? 1000 : 100;
661          Class cl = ConcurrentSkipListSet.class;
662  
663          NavigableSet<Integer> set = newSet(cl);
# Line 683 | Line 675 | public class ConcurrentSkipListSetTest e
675                     0, setSize - 1, true);
676      }
677  
678 <    static NavigableSet<Integer> newSet(Class cl) {
679 <        NavigableSet<Integer> result = null;
688 <        try {
689 <            result = (NavigableSet<Integer>) cl.newInstance();
690 <        } catch (Exception e) {
691 <            fail();
692 <        }
678 >    static NavigableSet<Integer> newSet(Class cl) throws Exception {
679 >        NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance();
680          assertEquals(result.size(), 0);
681          assertFalse(result.iterator().hasNext());
682          return result;
# Line 752 | Line 739 | public class ConcurrentSkipListSetTest e
739              } else {
740                  try {
741                      set.add(element);
742 <                    fail();
743 <                } catch (IllegalArgumentException e) {
757 <                    // expected
758 <                }
742 >                    shouldThrow();
743 >                } catch (IllegalArgumentException success) {}
744              }
745          }
746      }
# Line 888 | Line 873 | public class ConcurrentSkipListSetTest e
873                  // BitSet should support this! Test would run much faster
874                  while (element >= min) {
875                      if (bs.get(element))
876 <                        return(element);
876 >                        return element;
877                      element--;
878                  }
879                  return -1;
# Line 954 | Line 939 | public class ConcurrentSkipListSetTest e
939              assertEq(rs.last(),  -1);
940              try {
941                  set.first();
942 <                fail();
943 <            } catch (NoSuchElementException e) {
959 <                // expected
960 <            }
942 >                shouldThrow();
943 >            } catch (NoSuchElementException success) {}
944              try {
945                  set.last();
946 <                fail();
947 <            } catch (NoSuchElementException e) {
965 <                // expected
966 <            }
946 >                shouldThrow();
947 >            } catch (NoSuchElementException success) {}
948          }
949      }
950  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines