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

Comparing jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java (file contents):
Revision 1.10 by jsr166, Sat Nov 21 10:29:50 2009 UTC vs.
Revision 1.18 by jsr166, Tue Mar 15 19:47:06 2011 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.*;
# Line 11 | Line 11 | import java.io.*;
11  
12   public class ConcurrentSkipListSubSetTest 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(ConcurrentSkipListSubSetTest.class);
# Line 19 | Line 19 | public class ConcurrentSkipListSubSetTes
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 ConcurrentSkipListSubSetTes
27       * Create a set of given size containing consecutive
28       * Integers 0 ... n.
29       */
30 <    private NavigableSet populatedSet(int n) {
31 <        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
30 >    private NavigableSet<Integer> populatedSet(int n) {
31 >        ConcurrentSkipListSet<Integer> q =
32 >            new ConcurrentSkipListSet<Integer>();
33          assertTrue(q.isEmpty());
34  
35          for (int i = n-1; i >= 0; i-=2)
# Line 182 | Line 179 | public class ConcurrentSkipListSubSetTes
179              shouldThrow();
180          } catch (NullPointerException success) {}
181      }
182 +
183      /**
184       * addAll of a collection with null elements throws NPE
185       */
# Line 193 | Line 191 | public class ConcurrentSkipListSubSetTes
191              shouldThrow();
192          } catch (NullPointerException success) {}
193      }
194 +
195      /**
196       * addAll of a collection with any null elements throws NPE after
197       * possibly adding some elements
# Line 229 | Line 228 | public class ConcurrentSkipListSubSetTes
228      public void testPoll() {
229          NavigableSet q = populatedSet(SIZE);
230          for (int i = 0; i < SIZE; ++i) {
231 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
231 >            assertEquals(i, q.pollFirst());
232          }
233          assertNull(q.pollFirst());
234      }
# Line 240 | Line 239 | public class ConcurrentSkipListSubSetTes
239      public void testRemoveElement() {
240          NavigableSet q = populatedSet(SIZE);
241          for (int i = 1; i < SIZE; i+=2) {
242 <            assertTrue(q.remove(new Integer(i)));
242 >            assertTrue(q.contains(i));
243 >            assertTrue(q.remove(i));
244 >            assertFalse(q.contains(i));
245 >            assertTrue(q.contains(i-1));
246          }
247          for (int i = 0; i < SIZE; i+=2) {
248 <            assertTrue(q.remove(new Integer(i)));
249 <            assertFalse(q.remove(new Integer(i+1)));
248 >            assertTrue(q.contains(i));
249 >            assertTrue(q.remove(i));
250 >            assertFalse(q.contains(i));
251 >            assertFalse(q.remove(i+1));
252 >            assertFalse(q.contains(i+1));
253          }
254          assertTrue(q.isEmpty());
255      }
# Line 342 | Line 347 | public class ConcurrentSkipListSubSetTes
347  
348          Object e4 = q.lower(zero);
349          assertNull(e4);
345
350      }
351  
352      /**
# Line 361 | Line 365 | public class ConcurrentSkipListSubSetTes
365  
366          Object e4 = q.higher(six);
367          assertNull(e4);
364
368      }
369  
370      /**
# Line 380 | Line 383 | public class ConcurrentSkipListSubSetTes
383  
384          Object e4 = q.floor(zero);
385          assertNull(e4);
383
386      }
387  
388      /**
# Line 399 | Line 401 | public class ConcurrentSkipListSubSetTes
401  
402          Object e4 = q.ceiling(six);
403          assertNull(e4);
402
404      }
405  
406      /**
407 <     * toArray contains all elements
407 >     * toArray contains all elements in sorted order
408       */
409      public void testToArray() {
410          NavigableSet q = populatedSet(SIZE);
411          Object[] o = q.toArray();
411        Arrays.sort(o);
412          for (int i = 0; i < o.length; i++)
413 <            assertEquals(o[i], q.pollFirst());
413 >            assertSame(o[i], q.pollFirst());
414      }
415  
416      /**
417 <     * toArray(a) contains all elements
417 >     * toArray(a) contains all elements in sorted order
418       */
419      public void testToArray2() {
420 <        NavigableSet q = populatedSet(SIZE);
420 >        NavigableSet<Integer> q = populatedSet(SIZE);
421          Integer[] ints = new Integer[SIZE];
422 <        ints = (Integer[])q.toArray(ints);
423 <        Arrays.sort(ints);
422 >        Integer[] array = q.toArray(ints);
423 >        assertSame(ints, array);
424          for (int i = 0; i < ints.length; i++)
425 <            assertEquals(ints[i], q.pollFirst());
425 >            assertSame(ints[i], q.pollFirst());
426      }
427  
428      /**
# Line 456 | Line 456 | public class ConcurrentSkipListSubSetTes
456      /**
457       * iterator.remove removes current element
458       */
459 <    public void testIteratorRemove () {
459 >    public void testIteratorRemove() {
460          final NavigableSet q = set0();
461          q.add(new Integer(2));
462          q.add(new Integer(1));
# Line 688 | Line 688 | public class ConcurrentSkipListSubSetTes
688              shouldThrow();
689          } catch (NullPointerException success) {}
690      }
691 +
692      /**
693       * addAll of a collection with null elements throws NPE
694       */
# Line 699 | Line 700 | public class ConcurrentSkipListSubSetTes
700              shouldThrow();
701          } catch (NullPointerException success) {}
702      }
703 +
704      /**
705       * addAll of a collection with any null elements throws NPE after
706       * possibly adding some elements
# Line 735 | Line 737 | public class ConcurrentSkipListSubSetTes
737      public void testDescendingPoll() {
738          NavigableSet q = populatedSet(SIZE);
739          for (int i = 0; i < SIZE; ++i) {
740 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
740 >            assertEquals(i, q.pollFirst());
741          }
742          assertNull(q.pollFirst());
743      }
# Line 848 | Line 850 | public class ConcurrentSkipListSubSetTes
850  
851          Object e4 = q.lower(zero);
852          assertNull(e4);
851
853      }
854  
855      /**
# Line 867 | Line 868 | public class ConcurrentSkipListSubSetTes
868  
869          Object e4 = q.higher(m6);
870          assertNull(e4);
870
871      }
872  
873      /**
# Line 886 | Line 886 | public class ConcurrentSkipListSubSetTes
886  
887          Object e4 = q.floor(zero);
888          assertNull(e4);
889
889      }
890  
891      /**
# Line 905 | Line 904 | public class ConcurrentSkipListSubSetTes
904  
905          Object e4 = q.ceiling(m6);
906          assertNull(e4);
908
907      }
908  
909      /**
# Line 925 | Line 923 | public class ConcurrentSkipListSubSetTes
923      public void testDescendingToArray2() {
924          NavigableSet q = populatedSet(SIZE);
925          Integer[] ints = new Integer[SIZE];
926 <        ints = (Integer[])q.toArray(ints);
926 >        assertSame(ints, q.toArray(ints));
927          Arrays.sort(ints);
928          for (int i = 0; i < ints.length; i++)
929              assertEquals(ints[i], q.pollFirst());
# Line 962 | Line 960 | public class ConcurrentSkipListSubSetTes
960      /**
961       * iterator.remove removes current element
962       */
963 <    public void testDescendingIteratorRemove () {
963 >    public void testDescendingIteratorRemove() {
964          final NavigableSet q = dset0();
965          q.add(new Integer(2));
966          q.add(new Integer(1));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines