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.12 by jsr166, Tue Dec 1 09:48:13 2009 UTC vs.
Revision 1.22 by jsr166, Fri May 27 19:21:27 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 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 27 | 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 203 | 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 214 | 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 266 | Line 269 | public class ConcurrentSkipListSetTest e
269          assertNull(q.pollFirst());
270      }
271  
269
272      /**
273       * remove(x) removes x and returns true if present
274       */
275      public void testRemoveElement() {
276          ConcurrentSkipListSet q = populatedSet(SIZE);
277          for (int i = 1; i < SIZE; i+=2) {
278 <            assertTrue(q.remove(new Integer(i)));
278 >            assertTrue(q.contains(i));
279 >            assertTrue(q.remove(i));
280 >            assertFalse(q.contains(i));
281 >            assertTrue(q.contains(i-1));
282          }
283          for (int i = 0; i < SIZE; i+=2) {
284 <            assertTrue(q.remove(new Integer(i)));
285 <            assertFalse(q.remove(new Integer(i+1)));
284 >            assertTrue(q.contains(i));
285 >            assertTrue(q.remove(i));
286 >            assertFalse(q.contains(i));
287 >            assertFalse(q.remove(i+1));
288 >            assertFalse(q.contains(i+1));
289          }
290          assertTrue(q.isEmpty());
291      }
# Line 357 | Line 365 | public class ConcurrentSkipListSetTest e
365          }
366      }
367  
360
361
368      /**
369       * lower returns preceding element
370       */
# Line 432 | Line 438 | public class ConcurrentSkipListSetTest e
438      }
439  
440      /**
441 <     * toArray contains all elements
441 >     * toArray contains all elements in sorted order
442       */
443      public void testToArray() {
444          ConcurrentSkipListSet q = populatedSet(SIZE);
445          Object[] o = q.toArray();
440        Arrays.sort(o);
446          for (int i = 0; i < o.length; i++)
447 <            assertEquals(o[i], q.pollFirst());
447 >            assertSame(o[i], q.pollFirst());
448      }
449  
450      /**
451 <     * toArray(a) contains all elements
451 >     * toArray(a) contains all elements in sorted order
452       */
453      public void testToArray2() {
454 <        ConcurrentSkipListSet q = populatedSet(SIZE);
454 >        ConcurrentSkipListSet<Integer> q = populatedSet(SIZE);
455          Integer[] ints = new Integer[SIZE];
456 <        ints = (Integer[])q.toArray(ints);
457 <        Arrays.sort(ints);
456 >        Integer[] array = q.toArray(ints);
457 >        assertSame(ints, array);
458          for (int i = 0; i < ints.length; i++)
459 <            assertEquals(ints[i], q.pollFirst());
459 >            assertSame(ints[i], q.pollFirst());
460      }
461  
462      /**
# Line 485 | Line 490 | public class ConcurrentSkipListSetTest e
490      /**
491       * iterator.remove removes current element
492       */
493 <    public void testIteratorRemove () {
493 >    public void testIteratorRemove() {
494          final ConcurrentSkipListSet q = new ConcurrentSkipListSet();
495          q.add(new Integer(2));
496          q.add(new Integer(1));
# Line 501 | Line 506 | public class ConcurrentSkipListSetTest e
506          assertFalse(it.hasNext());
507      }
508  
504
509      /**
510       * toString contains toStrings of elements
511       */
# Line 509 | Line 513 | public class ConcurrentSkipListSetTest e
513          ConcurrentSkipListSet q = populatedSet(SIZE);
514          String s = q.toString();
515          for (int i = 0; i < SIZE; ++i) {
516 <            assertTrue(s.indexOf(String.valueOf(i)) >= 0);
516 >            assertTrue(s.contains(String.valueOf(i)));
517          }
518      }
519  
# Line 657 | Line 661 | public class ConcurrentSkipListSetTest e
661       * Subsets of subsets subdivide correctly
662       */
663      public void testRecursiveSubSets() throws Exception {
664 <        int setSize = 1000;
664 >        int setSize = expensiveTests ? 1000 : 100;
665          Class cl = ConcurrentSkipListSet.class;
666  
667          NavigableSet<Integer> set = newSet(cl);
# Line 838 | Line 842 | public class ConcurrentSkipListSetTest e
842       */
843      void check(NavigableSet<Integer> set,
844                        final int min, final int max, final boolean ascending) {
845 <       class ReferenceSet {
845 >        class ReferenceSet {
846              int lower(int element) {
847                  return ascending ?
848                      lowerAscending(element) : higherAscending(element);
# Line 873 | Line 877 | public class ConcurrentSkipListSetTest e
877                  // BitSet should support this! Test would run much faster
878                  while (element >= min) {
879                      if (bs.get(element))
880 <                        return(element);
880 >                        return element;
881                      element--;
882                  }
883                  return -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines