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.1 by dl, Tue Dec 28 16:15:59 2004 UTC vs.
Revision 1.11 by jsr166, Sun Nov 22 18:57:17 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();
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 34 | Line 30 | public class ConcurrentSkipListSetTest e
30      private ConcurrentSkipListSet populatedSet(int n) {
31          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
32          assertTrue(q.isEmpty());
33 <        for(int i = n-1; i >= 0; i-=2)
34 <            assertTrue(q.add(new Integer(i)));
35 <        for(int i = (n & 1); i < n; i+=2)
36 <            assertTrue(q.add(new Integer(i)));
33 >        for (int i = n-1; i >= 0; i-=2)
34 >            assertTrue(q.add(new Integer(i)));
35 >        for (int i = (n & 1); i < n; i+=2)
36 >            assertTrue(q.add(new Integer(i)));
37          assertFalse(q.isEmpty());
38 <        assertEquals(n, q.size());
38 >        assertEquals(n, q.size());
39          return q;
40      }
41  
# Line 54 | Line 50 | public class ConcurrentSkipListSetTest e
50          q.add(three);
51          q.add(four);
52          q.add(five);
53 <        assertEquals(5, q.size());
53 >        assertEquals(5, q.size());
54          return q;
55      }
56 <
56 >
57      /**
58       * A new set has unbounded capacity
59       */
# Line 72 | Line 68 | public class ConcurrentSkipListSetTest e
68          try {
69              ConcurrentSkipListSet q = new ConcurrentSkipListSet((Collection)null);
70              shouldThrow();
71 <        }
76 <        catch (NullPointerException success) {}
71 >        } catch (NullPointerException success) {}
72      }
73  
74      /**
# Line 84 | Line 79 | public class ConcurrentSkipListSetTest e
79              Integer[] ints = new Integer[SIZE];
80              ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
81              shouldThrow();
82 <        }
88 <        catch (NullPointerException success) {}
82 >        } catch (NullPointerException success) {}
83      }
84  
85      /**
# Line 98 | Line 92 | public class ConcurrentSkipListSetTest e
92                  ints[i] = new Integer(i);
93              ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
94              shouldThrow();
95 <        }
102 <        catch (NullPointerException success) {}
95 >        } catch (NullPointerException success) {}
96      }
97  
98      /**
99       * Set contains all elements of collection used to initialize
100       */
101      public void testConstructor6() {
102 <        try {
103 <            Integer[] ints = new Integer[SIZE];
104 <            for (int i = 0; i < SIZE; ++i)
105 <                ints[i] = new Integer(i);
106 <            ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
107 <            for (int i = 0; i < SIZE; ++i)
115 <                assertEquals(ints[i], q.pollFirst());
116 <        }
117 <        finally {}
102 >        Integer[] ints = new Integer[SIZE];
103 >        for (int i = 0; i < SIZE; ++i)
104 >            ints[i] = new Integer(i);
105 >        ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
106 >        for (int i = 0; i < SIZE; ++i)
107 >            assertEquals(ints[i], q.pollFirst());
108      }
109  
110      /**
111       * The comparator used in constructor is used
112       */
113      public void testConstructor7() {
114 <        try {
115 <            MyReverseComparator cmp = new MyReverseComparator();
116 <            ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp);
117 <            assertEquals(cmp, q.comparator());
118 <            Integer[] ints = new Integer[SIZE];
119 <            for (int i = 0; i < SIZE; ++i)
120 <                ints[i] = new Integer(i);
121 <            q.addAll(Arrays.asList(ints));
122 <            for (int i = SIZE-1; i >= 0; --i)
133 <                assertEquals(ints[i], q.pollFirst());
134 <        }
135 <        finally {}
114 >        MyReverseComparator cmp = new MyReverseComparator();
115 >        ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp);
116 >        assertEquals(cmp, q.comparator());
117 >        Integer[] ints = new Integer[SIZE];
118 >        for (int i = 0; i < SIZE; ++i)
119 >            ints[i] = new Integer(i);
120 >        q.addAll(Arrays.asList(ints));
121 >        for (int i = SIZE-1; i >= 0; --i)
122 >            assertEquals(ints[i], q.pollFirst());
123      }
124  
125      /**
# Line 168 | Line 155 | public class ConcurrentSkipListSetTest e
155       * add(null) throws NPE
156       */
157      public void testAddNull() {
158 <        try {
158 >        try {
159              ConcurrentSkipListSet q = new ConcurrentSkipListSet();
160              q.add(null);
161              shouldThrow();
162 <        } catch (NullPointerException success) { }  
162 >        } catch (NullPointerException success) {}
163      }
164  
165      /**
# Line 203 | Line 190 | public class ConcurrentSkipListSetTest e
190              q.add(new Object());
191              q.add(new Object());
192              shouldThrow();
193 <        }
207 <        catch(ClassCastException success) {}
193 >        } catch (ClassCastException success) {}
194      }
195  
196      /**
# Line 215 | Line 201 | public class ConcurrentSkipListSetTest e
201              ConcurrentSkipListSet q = new ConcurrentSkipListSet();
202              q.addAll(null);
203              shouldThrow();
204 <        }
219 <        catch (NullPointerException success) {}
204 >        } catch (NullPointerException success) {}
205      }
206      /**
207       * addAll of a collection with null elements throws NPE
# Line 227 | Line 212 | public class ConcurrentSkipListSetTest e
212              Integer[] ints = new Integer[SIZE];
213              q.addAll(Arrays.asList(ints));
214              shouldThrow();
215 <        }
231 <        catch (NullPointerException success) {}
215 >        } catch (NullPointerException success) {}
216      }
217      /**
218       * addAll of a collection with any null elements throws NPE after
# Line 242 | Line 226 | public class ConcurrentSkipListSetTest e
226                  ints[i] = new Integer(i);
227              q.addAll(Arrays.asList(ints));
228              shouldThrow();
229 <        }
246 <        catch (NullPointerException success) {}
229 >        } catch (NullPointerException success) {}
230      }
231  
232      /**
233       * Set contains all elements of successful addAll
234       */
235      public void testAddAll5() {
236 <        try {
237 <            Integer[] empty = new Integer[0];
238 <            Integer[] ints = new Integer[SIZE];
239 <            for (int i = 0; i < SIZE; ++i)
240 <                ints[i] = new Integer(SIZE-1-i);
241 <            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
242 <            assertFalse(q.addAll(Arrays.asList(empty)));
243 <            assertTrue(q.addAll(Arrays.asList(ints)));
244 <            for (int i = 0; i < SIZE; ++i)
262 <                assertEquals(new Integer(i), q.pollFirst());
263 <        }
264 <        finally {}
236 >        Integer[] empty = new Integer[0];
237 >        Integer[] ints = new Integer[SIZE];
238 >        for (int i = 0; i < SIZE; ++i)
239 >            ints[i] = new Integer(SIZE-1-i);
240 >        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
241 >        assertFalse(q.addAll(Arrays.asList(empty)));
242 >        assertTrue(q.addAll(Arrays.asList(ints)));
243 >        for (int i = 0; i < SIZE; ++i)
244 >            assertEquals(i, q.pollFirst());
245      }
246  
247      /**
# Line 270 | Line 250 | public class ConcurrentSkipListSetTest e
250      public void testPollFirst() {
251          ConcurrentSkipListSet q = populatedSet(SIZE);
252          for (int i = 0; i < SIZE; ++i) {
253 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
253 >            assertEquals(i, q.pollFirst());
254          }
255 <        assertNull(q.pollFirst());
255 >        assertNull(q.pollFirst());
256      }
257  
258      /**
# Line 281 | Line 261 | public class ConcurrentSkipListSetTest e
261      public void testPollLast() {
262          ConcurrentSkipListSet q = populatedSet(SIZE);
263          for (int i = SIZE-1; i >= 0; --i) {
264 <            assertEquals(i, ((Integer)q.pollLast()).intValue());
264 >            assertEquals(i, q.pollLast());
265          }
266 <        assertNull(q.pollFirst());
266 >        assertNull(q.pollFirst());
267      }
268  
269  
# Line 301 | Line 281 | public class ConcurrentSkipListSetTest e
281          }
282          assertTrue(q.isEmpty());
283      }
284 <        
284 >
285      /**
286       * contains(x) reports true when elements added but not yet removed
287       */
# Line 377 | Line 357 | public class ConcurrentSkipListSetTest e
357          }
358      }
359  
360 <    
360 >
361  
362      /**
363       * lower returns preceding element
# Line 460 | Line 440 | public class ConcurrentSkipListSetTest e
440       */
441      public void testToArray() {
442          ConcurrentSkipListSet q = populatedSet(SIZE);
443 <        Object[] o = q.toArray();
443 >        Object[] o = q.toArray();
444          Arrays.sort(o);
445 <        for(int i = 0; i < o.length; i++)
446 <            assertEquals(o[i], q.pollFirst());
445 >        for (int i = 0; i < o.length; i++)
446 >            assertEquals(o[i], q.pollFirst());
447      }
448  
449      /**
# Line 471 | Line 451 | public class ConcurrentSkipListSetTest e
451       */
452      public void testToArray2() {
453          ConcurrentSkipListSet q = populatedSet(SIZE);
454 <        Integer[] ints = new Integer[SIZE];
455 <        ints = (Integer[])q.toArray(ints);
454 >        Integer[] ints = new Integer[SIZE];
455 >        ints = (Integer[])q.toArray(ints);
456          Arrays.sort(ints);
457 <        for(int i = 0; i < ints.length; i++)
457 >        for (int i = 0; i < ints.length; i++)
458              assertEquals(ints[i], q.pollFirst());
459      }
460 <    
460 >
461      /**
462       * iterator iterates through all elements
463       */
464      public void testIterator() {
465          ConcurrentSkipListSet q = populatedSet(SIZE);
466          int i = 0;
467 <        Iterator it = q.iterator();
468 <        while(it.hasNext()) {
467 >        Iterator it = q.iterator();
468 >        while (it.hasNext()) {
469              assertTrue(q.contains(it.next()));
470              ++i;
471          }
# Line 498 | Line 478 | public class ConcurrentSkipListSetTest e
478      public void testEmptyIterator() {
479          ConcurrentSkipListSet q = new ConcurrentSkipListSet();
480          int i = 0;
481 <        Iterator it = q.iterator();
482 <        while(it.hasNext()) {
481 >        Iterator it = q.iterator();
482 >        while (it.hasNext()) {
483              assertTrue(q.contains(it.next()));
484              ++i;
485          }
# Line 535 | Line 515 | public class ConcurrentSkipListSetTest e
515          for (int i = 0; i < SIZE; ++i) {
516              assertTrue(s.indexOf(String.valueOf(i)) >= 0);
517          }
518 <    }        
518 >    }
519  
520      /**
521 <     * A deserialized serialized set has same elements
521 >     * A deserialized serialized set has same elements
522       */
523 <    public void testSerialization() {
523 >    public void testSerialization() throws Exception {
524          ConcurrentSkipListSet q = populatedSet(SIZE);
525 <        try {
526 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
527 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
528 <            out.writeObject(q);
529 <            out.close();
530 <
531 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
532 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
533 <            ConcurrentSkipListSet r = (ConcurrentSkipListSet)in.readObject();
534 <            assertEquals(q.size(), r.size());
535 <            while (!q.isEmpty())
556 <                assertEquals(q.pollFirst(), r.pollFirst());
557 <        } catch(Exception e){
558 <            e.printStackTrace();
559 <            unexpectedException();
560 <        }
525 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
526 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
527 >        out.writeObject(q);
528 >        out.close();
529 >
530 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
531 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
532 >        ConcurrentSkipListSet r = (ConcurrentSkipListSet)in.readObject();
533 >        assertEquals(q.size(), r.size());
534 >        while (!q.isEmpty())
535 >            assertEquals(q.pollFirst(), r.pollFirst());
536      }
537  
538      /**
# Line 679 | Line 654 | public class ConcurrentSkipListSetTest e
654          assertEquals(4, set.size());
655      }
656  
657 +    Random rnd = new Random(666);
658 +    BitSet bs;
659 +
660 +    /**
661 +     * Subsets of subsets subdivide correctly
662 +     */
663 +    public void testRecursiveSubSets() throws Exception {
664 +        int setSize = 1000;
665 +        Class cl = ConcurrentSkipListSet.class;
666 +
667 +        NavigableSet<Integer> set = newSet(cl);
668 +        bs = new BitSet(setSize);
669 +
670 +        populate(set, setSize);
671 +        check(set,                 0, setSize - 1, true);
672 +        check(set.descendingSet(), 0, setSize - 1, false);
673 +
674 +        mutateSet(set, 0, setSize - 1);
675 +        check(set,                 0, setSize - 1, true);
676 +        check(set.descendingSet(), 0, setSize - 1, false);
677 +
678 +        bashSubSet(set.subSet(0, true, setSize, false),
679 +                   0, setSize - 1, true);
680 +    }
681 +
682 +    static NavigableSet<Integer> newSet(Class cl) throws Exception {
683 +        NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance();
684 +        assertEquals(result.size(), 0);
685 +        assertFalse(result.iterator().hasNext());
686 +        return result;
687 +    }
688 +
689 +    void populate(NavigableSet<Integer> set, int limit) {
690 +        for (int i = 0, n = 2 * limit / 3; i < n; i++) {
691 +            int element = rnd.nextInt(limit);
692 +            put(set, element);
693 +        }
694 +    }
695 +
696 +    void mutateSet(NavigableSet<Integer> set, int min, int max) {
697 +        int size = set.size();
698 +        int rangeSize = max - min + 1;
699 +
700 +        // Remove a bunch of entries directly
701 +        for (int i = 0, n = rangeSize / 2; i < n; i++) {
702 +            remove(set, min - 5 + rnd.nextInt(rangeSize + 10));
703 +        }
704 +
705 +        // Remove a bunch of entries with iterator
706 +        for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
707 +            if (rnd.nextBoolean()) {
708 +                bs.clear(it.next());
709 +                it.remove();
710 +            }
711 +        }
712 +
713 +        // Add entries till we're back to original size
714 +        while (set.size() < size) {
715 +            int element = min + rnd.nextInt(rangeSize);
716 +            assertTrue(element >= min && element<= max);
717 +            put(set, element);
718 +        }
719 +    }
720 +
721 +    void mutateSubSet(NavigableSet<Integer> set, int min, int max) {
722 +        int size = set.size();
723 +        int rangeSize = max - min + 1;
724 +
725 +        // Remove a bunch of entries directly
726 +        for (int i = 0, n = rangeSize / 2; i < n; i++) {
727 +            remove(set, min - 5 + rnd.nextInt(rangeSize + 10));
728 +        }
729 +
730 +        // Remove a bunch of entries with iterator
731 +        for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
732 +            if (rnd.nextBoolean()) {
733 +                bs.clear(it.next());
734 +                it.remove();
735 +            }
736 +        }
737 +
738 +        // Add entries till we're back to original size
739 +        while (set.size() < size) {
740 +            int element = min - 5 + rnd.nextInt(rangeSize + 10);
741 +            if (element >= min && element<= max) {
742 +                put(set, element);
743 +            } else {
744 +                try {
745 +                    set.add(element);
746 +                    shouldThrow();
747 +                } catch (IllegalArgumentException success) {}
748 +            }
749 +        }
750 +    }
751 +
752 +    void put(NavigableSet<Integer> set, int element) {
753 +        if (set.add(element))
754 +            bs.set(element);
755 +    }
756 +
757 +    void remove(NavigableSet<Integer> set, int element) {
758 +        if (set.remove(element))
759 +            bs.clear(element);
760 +    }
761 +
762 +    void bashSubSet(NavigableSet<Integer> set,
763 +                    int min, int max, boolean ascending) {
764 +        check(set, min, max, ascending);
765 +        check(set.descendingSet(), min, max, !ascending);
766 +
767 +        mutateSubSet(set, min, max);
768 +        check(set, min, max, ascending);
769 +        check(set.descendingSet(), min, max, !ascending);
770 +
771 +        // Recurse
772 +        if (max - min < 2)
773 +            return;
774 +        int midPoint = (min + max) / 2;
775 +
776 +        // headSet - pick direction and endpoint inclusion randomly
777 +        boolean incl = rnd.nextBoolean();
778 +        NavigableSet<Integer> hm = set.headSet(midPoint, incl);
779 +        if (ascending) {
780 +            if (rnd.nextBoolean())
781 +                bashSubSet(hm, min, midPoint - (incl ? 0 : 1), true);
782 +            else
783 +                bashSubSet(hm.descendingSet(), min, midPoint - (incl ? 0 : 1),
784 +                           false);
785 +        } else {
786 +            if (rnd.nextBoolean())
787 +                bashSubSet(hm, midPoint + (incl ? 0 : 1), max, false);
788 +            else
789 +                bashSubSet(hm.descendingSet(), midPoint + (incl ? 0 : 1), max,
790 +                           true);
791 +        }
792 +
793 +        // tailSet - pick direction and endpoint inclusion randomly
794 +        incl = rnd.nextBoolean();
795 +        NavigableSet<Integer> tm = set.tailSet(midPoint,incl);
796 +        if (ascending) {
797 +            if (rnd.nextBoolean())
798 +                bashSubSet(tm, midPoint + (incl ? 0 : 1), max, true);
799 +            else
800 +                bashSubSet(tm.descendingSet(), midPoint + (incl ? 0 : 1), max,
801 +                           false);
802 +        } else {
803 +            if (rnd.nextBoolean()) {
804 +                bashSubSet(tm, min, midPoint - (incl ? 0 : 1), false);
805 +            } else {
806 +                bashSubSet(tm.descendingSet(), min, midPoint - (incl ? 0 : 1),
807 +                           true);
808 +            }
809 +        }
810 +
811 +        // subSet - pick direction and endpoint inclusion randomly
812 +        int rangeSize = max - min + 1;
813 +        int[] endpoints = new int[2];
814 +        endpoints[0] = min + rnd.nextInt(rangeSize);
815 +        endpoints[1] = min + rnd.nextInt(rangeSize);
816 +        Arrays.sort(endpoints);
817 +        boolean lowIncl = rnd.nextBoolean();
818 +        boolean highIncl = rnd.nextBoolean();
819 +        if (ascending) {
820 +            NavigableSet<Integer> sm = set.subSet(
821 +                endpoints[0], lowIncl, endpoints[1], highIncl);
822 +            if (rnd.nextBoolean())
823 +                bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1),
824 +                           endpoints[1] - (highIncl ? 0 : 1), true);
825 +            else
826 +                bashSubSet(sm.descendingSet(), endpoints[0] + (lowIncl ? 0 : 1),
827 +                           endpoints[1] - (highIncl ? 0 : 1), false);
828 +        } else {
829 +            NavigableSet<Integer> sm = set.subSet(
830 +                endpoints[1], highIncl, endpoints[0], lowIncl);
831 +            if (rnd.nextBoolean())
832 +                bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1),
833 +                           endpoints[1] - (highIncl ? 0 : 1), false);
834 +            else
835 +                bashSubSet(sm.descendingSet(), endpoints[0] + (lowIncl ? 0 : 1),
836 +                           endpoints[1] - (highIncl ? 0 : 1), true);
837 +        }
838 +    }
839 +
840 +    /**
841 +     * min and max are both inclusive.  If max < min, interval is empty.
842 +     */
843 +    void check(NavigableSet<Integer> set,
844 +                      final int min, final int max, final boolean ascending) {
845 +       class ReferenceSet {
846 +            int lower(int element) {
847 +                return ascending ?
848 +                    lowerAscending(element) : higherAscending(element);
849 +            }
850 +            int floor(int element) {
851 +                return ascending ?
852 +                    floorAscending(element) : ceilingAscending(element);
853 +            }
854 +            int ceiling(int element) {
855 +                return ascending ?
856 +                    ceilingAscending(element) : floorAscending(element);
857 +            }
858 +            int higher(int element) {
859 +                return ascending ?
860 +                    higherAscending(element) : lowerAscending(element);
861 +            }
862 +            int first() {
863 +                return ascending ? firstAscending() : lastAscending();
864 +            }
865 +            int last() {
866 +                return ascending ? lastAscending() : firstAscending();
867 +            }
868 +            int lowerAscending(int element) {
869 +                return floorAscending(element - 1);
870 +            }
871 +            int floorAscending(int element) {
872 +                if (element < min)
873 +                    return -1;
874 +                else if (element > max)
875 +                    element = max;
876 +
877 +                // BitSet should support this! Test would run much faster
878 +                while (element >= min) {
879 +                    if (bs.get(element))
880 +                        return(element);
881 +                    element--;
882 +                }
883 +                return -1;
884 +            }
885 +            int ceilingAscending(int element) {
886 +                if (element < min)
887 +                    element = min;
888 +                else if (element > max)
889 +                    return -1;
890 +                int result = bs.nextSetBit(element);
891 +                return result > max ? -1 : result;
892 +            }
893 +            int higherAscending(int element) {
894 +                return ceilingAscending(element + 1);
895 +            }
896 +            private int firstAscending() {
897 +                int result = ceilingAscending(min);
898 +                return result > max ? -1 : result;
899 +            }
900 +            private int lastAscending() {
901 +                int result = floorAscending(max);
902 +                return result < min ? -1 : result;
903 +            }
904 +        }
905 +        ReferenceSet rs = new ReferenceSet();
906 +
907 +        // Test contents using containsElement
908 +        int size = 0;
909 +        for (int i = min; i <= max; i++) {
910 +            boolean bsContainsI = bs.get(i);
911 +            assertEquals(bsContainsI, set.contains(i));
912 +            if (bsContainsI)
913 +                size++;
914 +        }
915 +        assertEquals(set.size(), size);
916 +
917 +        // Test contents using contains elementSet iterator
918 +        int size2 = 0;
919 +        int previousElement = -1;
920 +        for (int element : set) {
921 +            assertTrue(bs.get(element));
922 +            size2++;
923 +            assertTrue(previousElement < 0 || (ascending ?
924 +                element - previousElement > 0 : element - previousElement < 0));
925 +            previousElement = element;
926 +        }
927 +        assertEquals(size2, size);
928 +
929 +        // Test navigation ops
930 +        for (int element = min - 1; element <= max + 1; element++) {
931 +            assertEq(set.lower(element), rs.lower(element));
932 +            assertEq(set.floor(element), rs.floor(element));
933 +            assertEq(set.higher(element), rs.higher(element));
934 +            assertEq(set.ceiling(element), rs.ceiling(element));
935 +        }
936 +
937 +        // Test extrema
938 +        if (set.size() != 0) {
939 +            assertEq(set.first(), rs.first());
940 +            assertEq(set.last(), rs.last());
941 +        } else {
942 +            assertEq(rs.first(), -1);
943 +            assertEq(rs.last(),  -1);
944 +            try {
945 +                set.first();
946 +                shouldThrow();
947 +            } catch (NoSuchElementException success) {}
948 +            try {
949 +                set.last();
950 +                shouldThrow();
951 +            } catch (NoSuchElementException success) {}
952 +        }
953 +    }
954 +
955 +    static void assertEq(Integer i, int j) {
956 +        if (i == null)
957 +            assertEquals(j, -1);
958 +        else
959 +            assertEquals((int) i, j);
960 +    }
961 +
962 +    static boolean eq(Integer i, int j) {
963 +        return i == null ? j == -1 : i == j;
964 +    }
965 +
966   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines