Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   package org.mapdb;
   
   /*
    * Written by Doug Lea with assistance from members of JCP JSR-166
    * Expert Group and released to the public domain, as explained at
    * http://creativecommons.org/publicdomain/zero/1.0/
    */
   
   import junit.framework.Test;
  
  import java.util.*;
  
  public class BTreeSet3Test extends JSR166TestCase {
      public static void main(String[] args) {
          junit.textui.TestRunner.run(suite());
      }
      public static Test suite() {
          return new TestSuite(BTreeSet3Test.class);
      }
  
      static class MyReverseComparator implements Comparator {
          public int compare(Object xObject y) {
              return ((Comparable)y).compareTo(x);
          }
      }

    
Returns a new set of given size containing consecutive Integers 0 ... n.
  
      private NavigableSet<IntegerpopulatedSet(int n) {
          NavigableSet<Integerq =
                  DBMaker.newMemoryDB().make().getTreeSet("test");
          assertTrue(q.isEmpty());
  
          for (int i = n-1; i >= 0; i-=2)
              assertTrue(q.add(new Integer(i)));
          for (int i = (n & 1); i < ni+=2)
              assertTrue(q.add(new Integer(i)));
          assertTrue(q.add(new Integer(-n)));
          assertTrue(q.add(new Integer(n)));
          NavigableSet s = q.subSet(new Integer(0), truenew Integer(n), false);
          assertFalse(s.isEmpty());
          assertEquals(ns.size());
          return s;
      }

    
Returns a new set of first 5 ints.
  
      private NavigableSet set5() {
          NavigableSet q = DBMaker.newMemoryDB().make().getTreeSet("test");
          assertTrue(q.isEmpty());
          q.add();
          q.add();
          q.add();
          q.add();
          q.add();
          q.add();
          q.add();
          NavigableSet s = q.subSet(truefalse);
          assertEquals(5, s.size());
          return s;
      }

    
Returns a new set of first 5 negative ints.
  
      private NavigableSet dset5() {
          NavigableSet q = DBMaker.newMemoryDB().make().getTreeSet("test");
          assertTrue(q.isEmpty());
          q.add();
          q.add();
          q.add();
          q.add();
          q.add();
          NavigableSet s = q.descendingSet();
          assertEquals(5, s.size());
          return s;
      }
  
      private static NavigableSet set0() {
          NavigableSet set = DBMaker.newMemoryDB().make().getTreeSet("test");
          assertTrue(set.isEmpty());
          return set.tailSet(true);
      }
  
      private static NavigableSet dset0() {
          NavigableSet set = DBMaker.newMemoryDB().make().getTreeSet("test");
          assertTrue(set.isEmpty());
          return set;
      }

    
A new set has unbounded capacity
  
      public void testConstructor1() {
          assertEquals(0, set0().size());
     }

    
isEmpty is true before add, false after
 
     public void testEmpty() {
         NavigableSet q = set0();
         assertTrue(q.isEmpty());
         q.add(new Integer(1));
         assertFalse(q.isEmpty());
         q.add(new Integer(2));
         q.pollFirst();
         q.pollFirst();
         assertTrue(q.isEmpty());
     }

    
size changes when elements added and removed
 
     public void testSize() {
         NavigableSet q = populatedSet();
         for (int i = 0; i < ; ++i) {
             assertEquals(-iq.size());
             q.pollFirst();
         }
         for (int i = 0; i < ; ++i) {
             assertEquals(iq.size());
             q.add(new Integer(i));
         }
     }

    
add(null) throws NPE
 
     public void testAddNull() {
         try {
             NavigableSet q = set0();
             q.add(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
Add of comparable element succeeds
 
     public void testAdd() {
         NavigableSet q = set0();
         assertTrue(q.add());
     }

    
Add of duplicate element fails
 
     public void testAddDup() {
         NavigableSet q = set0();
         assertTrue(q.add());
         assertFalse(q.add());
     }

    
Add of non-Comparable throws CCE
 
     public void testAddNonComparable() {
         try {
             NavigableSet q = set0();
             q.add(new Object());
             q.add(new Object());
             q.add(new Object());
             shouldThrow();
         } catch (ClassCastException success) {}
     }

    
addAll(null) throws NPE
 
     public void testAddAll1() {
         try {
             NavigableSet q = set0();
             q.addAll(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
addAll of a collection with null elements throws NPE
 
     public void testAddAll2() {
         try {
             NavigableSet q = set0();
             Integer[] ints = new Integer[];
             q.addAll(Arrays.asList(ints));
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
addAll of a collection with any null elements throws NPE after possibly adding some elements
 
     public void testAddAll3() {
         try {
             NavigableSet q = set0();
             Integer[] ints = new Integer[];
             for (int i = 0; i < -1; ++i)
                 ints[i] = new Integer(i+);
             q.addAll(Arrays.asList(ints));
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
Set contains all elements of successful addAll
 
     public void testAddAll5() {
         Integer[] empty = new Integer[0];
         Integer[] ints = new Integer[];
         for (int i = 0; i < ; ++i)
             ints[i] = new Integer(-1- i);
         NavigableSet q = set0();
         assertFalse(q.addAll(Arrays.asList(empty)));
         assertTrue(q.addAll(Arrays.asList(ints)));
         for (int i = 0; i < ; ++i)
             assertEquals(new Integer(i), q.pollFirst());
     }

    
poll succeeds unless empty
 
     public void testPoll() {
         NavigableSet q = populatedSet();
         for (int i = 0; i < ; ++i) {
             assertEquals(iq.pollFirst());
         }
         assertNull(q.pollFirst());
     }

    
remove(x) removes x and returns true if present
 
     public void testRemoveElement() {
         NavigableSet q = populatedSet();
         for (int i = 1; i < i+=2) {
             assertTrue(q.contains(i));
             assertTrue(q.remove(i));
             assertFalse(q.contains(i));
             assertTrue(q.contains(i-1));
         }
         for (int i = 0; i < i+=2) {
             assertTrue(q.contains(i));
             assertTrue(q.remove(i));
             assertFalse(q.contains(i));
             assertFalse(q.remove(i+1));
             assertFalse(q.contains(i+1));
         }
         assertTrue(q.isEmpty());
     }

    
contains(x) reports true when elements added but not yet removed
 
     public void testContains() {
         NavigableSet q = populatedSet();
         for (int i = 0; i < ; ++i) {
             assertTrue(q.contains(new Integer(i)));
             q.pollFirst();
             assertFalse(q.contains(new Integer(i)));
         }
     }

    
clear removes all elements
 
     public void testClear() {
         NavigableSet q = populatedSet();
         q.clear();
         assertTrue(q.isEmpty());
         assertEquals(0, q.size());
         q.add(new Integer(1));
         assertFalse(q.isEmpty());
         q.clear();
         assertTrue(q.isEmpty());
     }

    
containsAll(c) is true when c contains a subset of elements
 
     public void testContainsAll() {
         NavigableSet q = populatedSet();
         NavigableSet p = set0();
         for (int i = 0; i < ; ++i) {
             assertTrue(q.containsAll(p));
             assertFalse(p.containsAll(q));
             p.add(new Integer(i));
         }
         assertTrue(p.containsAll(q));
     }

    
retainAll(c) retains only those elements of c and reports true if changed
 
     public void testRetainAll() {
         NavigableSet q = populatedSet();
         NavigableSet p = populatedSet();
         for (int i = 0; i < ; ++i) {
             boolean changed = q.retainAll(p);
             if (i == 0)
                 assertFalse(changed);
             else
                 assertTrue(changed);
 
             assertTrue(q.containsAll(p));
             assertEquals(-iq.size());
             p.pollFirst();
         }
     }

    
removeAll(c) removes only those elements of c and reports true if changed
 
     public void testRemoveAll() {
         for (int i = 1; i < ; ++i) {
             NavigableSet q = populatedSet();
             NavigableSet p = populatedSet(i);
             assertTrue(q.removeAll(p));
             assertEquals(-iq.size());
             for (int j = 0; j < i; ++j) {
                 Integer I = (Integer)(p.pollFirst());
                 assertFalse(q.contains(I));
             }
         }
     }

    
lower returns preceding element
 
     public void testLower() {
         NavigableSet q = set5();
         Object e1 = q.lower();
         assertEquals(e1);
 
         Object e2 = q.lower();
         assertEquals(e2);
 
         Object e3 = q.lower();
         assertNull(e3);
 
         Object e4 = q.lower();
         assertNull(e4);
     }

    
higher returns next element
 
     public void testHigher() {
         NavigableSet q = set5();
         Object e1 = q.higher();
         assertEquals(e1);
 
         Object e2 = q.higher();
         assertEquals(e2);
 
         Object e3 = q.higher();
         assertNull(e3);
 
         Object e4 = q.higher();
         assertNull(e4);
     }

    
floor returns preceding element
 
     public void testFloor() {
         NavigableSet q = set5();
         Object e1 = q.floor();
         assertEquals(e1);
 
         Object e2 = q.floor();
         assertEquals(e2);
 
         Object e3 = q.floor();
         assertEquals(e3);
 
         Object e4 = q.floor();
         assertNull(e4);
     }

    
ceiling returns next element
 
     public void testCeiling() {
         NavigableSet q = set5();
         Object e1 = q.ceiling();
         assertEquals(e1);
 
         Object e2 = q.ceiling();
         assertEquals(e2);
 
         Object e3 = q.ceiling();
         assertEquals(e3);
 
         Object e4 = q.ceiling();
         assertNull(e4);
     }

    
toArray contains all elements in sorted order
 
     public void testToArray() {
         NavigableSet q = populatedSet();
         Object[] o = q.toArray();
         for (int i = 0; i < o.lengthi++)
             assertSame(o[i], q.pollFirst());
     }

    
toArray(a) contains all elements in sorted order
 
     public void testToArray2() {
         NavigableSet<Integerq = populatedSet();
         Integer[] ints = new Integer[];
         Integer[] array = q.toArray(ints);
         assertSame(intsarray);
         for (int i = 0; i < ints.lengthi++)
             assertSame(ints[i], q.pollFirst());
     }

    
iterator iterates through all elements
 
     public void testIterator() {
         NavigableSet q = populatedSet();
         int i = 0;
         Iterator it = q.iterator();
         while (it.hasNext()) {
             assertTrue(q.contains(it.next()));
             ++i;
         }
         assertEquals(i);
     }

    
iterator of empty set has no elements
 
     public void testEmptyIterator() {
         NavigableSet q = set0();
         int i = 0;
         Iterator it = q.iterator();
         while (it.hasNext()) {
             assertTrue(q.contains(it.next()));
             ++i;
         }
         assertEquals(0, i);
     }

    
iterator.remove removes current element
 
     public void testIteratorRemove() {
         final NavigableSet q = set0();
         q.add(new Integer(2));
         q.add(new Integer(1));
         q.add(new Integer(3));
 
         Iterator it = q.iterator();
         it.next();
         it.remove();
 
         it = q.iterator();
         assertEquals(it.next(), new Integer(2));
         assertEquals(it.next(), new Integer(3));
         assertFalse(it.hasNext());
     }

    
toString contains toStrings of elements
 
     public void testToString() {
         NavigableSet q = populatedSet();
         String s = q.toString();
         for (int i = 0; i < ; ++i) {
             assertTrue(s.contains(String.valueOf(i)));
         }
     }
 
 //    /**
 //     * A deserialized serialized set has same elements
 //     */
 //    public void testSerialization() throws Exception {
 //        NavigableSet x = populatedSet(SIZE);
 //        NavigableSet y = serialClone(x);
 //
 //        assertNotSame(y, x);
 //        assertEquals(x.size(), y.size());
 //        assertEquals(x, y);
 //        assertEquals(y, x);
 //        while (!x.isEmpty()) {
 //            assertFalse(y.isEmpty());
 //            assertEquals(x.pollFirst(), y.pollFirst());
 //        }
 //        assertTrue(y.isEmpty());
 //    }
 //
     
subSet returns set with keys in requested range
 
     public void testSubSetContents() {
         NavigableSet set = set5();
         SortedSet sm = set.subSet();
         assertEquals(sm.first());
         assertEquals(sm.last());
         assertEquals(2, sm.size());
         assertFalse(sm.contains());
         assertTrue(sm.contains());
         assertTrue(sm.contains());
         assertFalse(sm.contains());
         assertFalse(sm.contains());
         Iterator i = sm.iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         assertFalse(i.hasNext());
         Iterator j = sm.iterator();
         j.next();
         j.remove();
         assertFalse(set.contains());
         assertEquals(4, set.size());
         assertEquals(1, sm.size());
         assertEquals(sm.first());
         assertEquals(sm.last());
         assertTrue(sm.remove());
         assertTrue(sm.isEmpty());
         assertEquals(3, set.size());
     }
 
     public void testSubSetContents2() {
         NavigableSet set = set5();
         SortedSet sm = set.subSet();
         assertEquals(1, sm.size());
         assertEquals(sm.first());
         assertEquals(sm.last());
         assertFalse(sm.contains());
         assertTrue(sm.contains());
         assertFalse(sm.contains());
         assertFalse(sm.contains());
         assertFalse(sm.contains());
         Iterator i = sm.iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(k);
         assertFalse(i.hasNext());
         Iterator j = sm.iterator();
         j.next();
         j.remove();
         assertFalse(set.contains());
         assertEquals(4, set.size());
         assertEquals(0, sm.size());
         assertTrue(sm.isEmpty());
         assertFalse(sm.remove());
         assertEquals(4, set.size());
     }

    
headSet returns set with keys in requested range
 
     public void testHeadSetContents() {
         NavigableSet set = set5();
         SortedSet sm = set.headSet();
         assertTrue(sm.contains());
         assertTrue(sm.contains());
         assertTrue(sm.contains());
         assertFalse(sm.contains());
         assertFalse(sm.contains());
         Iterator i = sm.iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         assertFalse(i.hasNext());
         sm.clear();
         assertTrue(sm.isEmpty());
         assertEquals(2, set.size());
         assertEquals(set.first());
     }

    
tailSet returns set with keys in requested range
 
     public void testTailSetContents() {
         NavigableSet set = set5();
         SortedSet sm = set.tailSet();
         assertFalse(sm.contains());
         assertTrue(sm.contains());
         assertTrue(sm.contains());
         assertTrue(sm.contains());
         assertTrue(sm.contains());
         Iterator i = sm.iterator();
         Object k;
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         k = (Integer)(i.next());
         assertEquals(k);
         assertFalse(i.hasNext());
 
         SortedSet ssm = sm.tailSet();
         assertEquals(ssm.first());
         assertEquals(ssm.last());
         assertTrue(ssm.remove());
         assertEquals(1, ssm.size());
         assertEquals(3, sm.size());
         assertEquals(4, set.size());
     }

    
size changes when elements added and removed
 
     public void testDescendingSize() {
         NavigableSet q = populatedSet();
         for (int i = 0; i < ; ++i) {
             assertEquals(-iq.size());
             q.pollFirst();
         }
         for (int i = 0; i < ; ++i) {
             assertEquals(iq.size());
             q.add(new Integer(i));
         }
     }

    
add(null) throws NPE
 
     public void testDescendingAddNull() {
         try {
             NavigableSet q = dset0();
             q.add(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
Add of comparable element succeeds
 
     public void testDescendingAdd() {
         NavigableSet q = dset0();
         assertTrue(q.add());
     }

    
Add of duplicate element fails
 
     public void testDescendingAddDup() {
         NavigableSet q = dset0();
         assertTrue(q.add());
         assertFalse(q.add());
     }

    
Add of non-Comparable throws CCE
 
     public void testDescendingAddNonComparable() {
         try {
             NavigableSet q = dset0();
             q.add(new Object());
             q.add(new Object());
             q.add(new Object());
             shouldThrow();
         } catch (ClassCastException success) {}
     }

    
addAll(null) throws NPE
 
     public void testDescendingAddAll1() {
         try {
             NavigableSet q = dset0();
             q.addAll(null);
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
addAll of a collection with null elements throws NPE
 
     public void testDescendingAddAll2() {
         try {
             NavigableSet q = dset0();
             Integer[] ints = new Integer[];
             q.addAll(Arrays.asList(ints));
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
addAll of a collection with any null elements throws NPE after possibly adding some elements
 
     public void testDescendingAddAll3() {
         try {
             NavigableSet q = dset0();
             Integer[] ints = new Integer[];
             for (int i = 0; i < -1; ++i)
                 ints[i] = new Integer(i+);
             q.addAll(Arrays.asList(ints));
             shouldThrow();
         } catch (NullPointerException success) {}
     }

    
Set contains all elements of successful addAll
 
     public void testDescendingAddAll5() {
         Integer[] empty = new Integer[0];
         Integer[] ints = new Integer[];
         for (int i = 0; i < ; ++i)
             ints[i] = new Integer(-1- i);
         NavigableSet q = dset0();
         assertFalse(q.addAll(Arrays.asList(empty)));
         assertTrue(q.addAll(Arrays.asList(ints)));
         for (int i = 0; i < ; ++i)
             assertEquals(new Integer(i), q.pollFirst());
     }

    
poll succeeds unless empty
 
     public void testDescendingPoll() {
         NavigableSet q = populatedSet();
         for (int i = 0; i < ; ++i) {
             assertEquals(iq.pollFirst());
         }
         assertNull(q.pollFirst());
     }

    
remove(x) removes x and returns true if present
 
     public void testDescendingRemoveElement() {
         NavigableSet q = populatedSet();
         for (int i = 1; i < i+=2) {
             assertTrue(q.remove(new Integer(i)));
         }
         for (int i = 0; i < i+=2) {
             assertTrue(q.remove(new Integer(i)));
             assertFalse(q.remove(new Integer(i+1)));
         }
         assertTrue(q.isEmpty());
     }

    
contains(x) reports true when elements added but not yet removed
 
     public void testDescendingContains() {
         NavigableSet q = populatedSet();
         for (int i = 0; i < ; ++i) {
             assertTrue(q.contains(new Integer(i)));
             q.pollFirst();
             assertFalse(q.contains(new Integer(i)));
         }
     }

    
clear removes all elements
 
     public void testDescendingClear() {
         NavigableSet q = populatedSet();
         q.clear();
         assertTrue(q.isEmpty());
         assertEquals(0, q.size());
         q.add(new Integer(1));
         assertFalse(q.isEmpty());
         q.clear();
         assertTrue(q.isEmpty());
     }

    
containsAll(c) is true when c contains a subset of elements
 
     public void testDescendingContainsAll() {
         NavigableSet q = populatedSet();
         NavigableSet p = dset0();
         for (int i = 0; i < ; ++i) {
             assertTrue(q.containsAll(p));
             assertFalse(p.containsAll(q));
             p.add(new Integer(i));
         }
         assertTrue(p.containsAll(q));
     }

    
retainAll(c) retains only those elements of c and reports true if changed
 
     public void testDescendingRetainAll() {
         NavigableSet q = populatedSet();
         NavigableSet p = populatedSet();
         for (int i = 0; i < ; ++i) {
             boolean changed = q.retainAll(p);
             if (i == 0)
                 assertFalse(changed);
             else
                 assertTrue(changed);
 
             assertTrue(q.containsAll(p));
             assertEquals(-iq.size());
             p.pollFirst();
         }
     }

    
removeAll(c) removes only those elements of c and reports true if changed
 
     public void testDescendingRemoveAll() {
         for (int i = 1; i < ; ++i) {
             NavigableSet q = populatedSet();
             NavigableSet p = populatedSet(i);
             assertTrue(q.removeAll(p));
             assertEquals(-iq.size());
             for (int j = 0; j < i; ++j) {
                 Integer I = (Integer)(p.pollFirst());
                 assertFalse(q.contains(I));
             }
         }
     }

    
lower returns preceding element
 
     public void testDescendingLower() {
         NavigableSet q = dset5();
         Object e1 = q.lower();
         assertEquals(e1);
 
         Object e2 = q.lower();
         assertEquals(e2);
 
         Object e3 = q.lower();
         assertNull(e3);
 
         Object e4 = q.lower();
         assertNull(e4);
     }

    
higher returns next element
 
     public void testDescendingHigher() {
         NavigableSet q = dset5();
         Object e1 = q.higher();
         assertEquals(e1);
 
         Object e2 = q.higher();
         assertEquals(e2);
 
         Object e3 = q.higher();
         assertNull(e3);
 
         Object e4 = q.higher();
         assertNull(e4);
     }

    
floor returns preceding element
 
     public void testDescendingFloor() {
         NavigableSet q = dset5();
         Object e1 = q.floor();
         assertEquals(e1);
 
         Object e2 = q.floor();
         assertEquals(e2);
 
         Object e3 = q.floor();
         assertEquals(e3);
 
         Object e4 = q.floor();
         assertNull(e4);
     }

    
ceiling returns next element
 
     public void testDescendingCeiling() {
         NavigableSet q = dset5();
         Object e1 = q.ceiling();
         assertEquals(e1);
 
         Object e2 = q.ceiling();
         assertEquals(e2);
 
         Object e3 = q.ceiling();
         assertEquals(e3);
 
         Object e4 = q.ceiling();
         assertNull(e4);
     }

    
toArray contains all elements
 
     public void testDescendingToArray() {
         NavigableSet q = populatedSet();
         Object[] o = q.toArray();
         Arrays.sort(o);
         for (int i = 0; i < o.lengthi++)
             assertEquals(o[i], q.pollFirst());
     }

    
toArray(a) contains all elements
 
     public void testDescendingToArray2() {
         NavigableSet q = populatedSet();
         Integer[] ints = new Integer[];
         assertSame(intsq.toArray(ints));
         Arrays.sort(ints);
         for (int i = 0; i < ints.lengthi++)
             assertEquals(ints[i], q.pollFirst());
     }

    
iterator iterates through all elements
 
     public void testDescendingIterator() {
         NavigableSet q = populatedSet();
         int i = 0;
         Iterator it = q.iterator();
         while (it.hasNext()) {
             assertTrue(q.contains(it.next()));
             ++i;
         }
         assertEquals(i);
     }

    
iterator of empty set has no elements
 
     public void testDescendingEmptyIterator() {
         NavigableSet q = dset0();
         int i = 0;
         Iterator it = q.iterator();
         while (it.hasNext()) {
             assertTrue(q.contains(it.next()));
             ++i;
         }
         assertEquals(0, i);
     }

    
iterator.remove removes current element
 
     public void testDescendingIteratorRemove() {
         final NavigableSet q = dset0();
         q.add(new Integer(2));
         q.add(new Integer(1));
         q.add(new Integer(3));
 
         Iterator it = q.iterator();
         it.next();
         it.remove();
 
         it = q.iterator();
         assertEquals(it.next(), new Integer(2));
         assertEquals(it.next(), new Integer(3));
         assertFalse(it.hasNext());
     }

    
toString contains toStrings of elements
 
     public void testDescendingToString() {
         NavigableSet q = populatedSet();
         String s = q.toString();
         for (int i = 0; i < ; ++i) {
             assertTrue(s.contains(String.valueOf(i)));
         }
     }
 //
 //    /**
 //     * A deserialized serialized set has same elements
 //     */
 //    public void testDescendingSerialization() throws Exception {
 //        NavigableSet x = dset5();
 //        NavigableSet y = serialClone(x);
 //
 //        assertNotSame(y, x);
 //        assertEquals(x.size(), y.size());
 //        assertEquals(x, y);
 //        assertEquals(y, x);
 //        while (!x.isEmpty()) {
 //            assertFalse(y.isEmpty());
 //            assertEquals(x.pollFirst(), y.pollFirst());
 //        }
 //        assertTrue(y.isEmpty());
//    }

    
subSet returns set with keys in requested range
    public void testDescendingSubSetContents() {
        NavigableSet set = dset5();
        SortedSet sm = set.subSet();
        assertEquals(sm.first());
        assertEquals(sm.last());
        assertEquals(2, sm.size());
        assertFalse(sm.contains());
        assertTrue(sm.contains());
        assertTrue(sm.contains());
        assertFalse(sm.contains());
        assertFalse(sm.contains());
        Iterator i = sm.iterator();
        Object k;
        k = (Integer)(i.next());
        assertEquals(k);
        k = (Integer)(i.next());
        assertEquals(k);
        assertFalse(i.hasNext());
        Iterator j = sm.iterator();
        j.next();
        j.remove();
        assertFalse(set.contains());
        assertEquals(4, set.size());
        assertEquals(1, sm.size());
        assertEquals(sm.first());
        assertEquals(sm.last());
        assertTrue(sm.remove());
        assertTrue(sm.isEmpty());
        assertEquals(3, set.size());
    }
    public void testDescendingSubSetContents2() {
        NavigableSet set = dset5();
        SortedSet sm = set.subSet();
        assertEquals(1, sm.size());
        assertEquals(sm.first());
        assertEquals(sm.last());
        assertFalse(sm.contains());
        assertTrue(sm.contains());
        assertFalse(sm.contains());
        assertFalse(sm.contains());
        assertFalse(sm.contains());
        Iterator i = sm.iterator();
        Object k;
        k = (Integer)(i.next());
        assertEquals(k);
        assertFalse(i.hasNext());
        Iterator j = sm.iterator();
        j.next();
        j.remove();
        assertFalse(set.contains());
        assertEquals(4, set.size());
        assertEquals(0, sm.size());
        assertTrue(sm.isEmpty());
        assertFalse(sm.remove());
        assertEquals(4, set.size());
    }

    
headSet returns set with keys in requested range
    public void testDescendingHeadSetContents() {
        NavigableSet set = dset5();
        SortedSet sm = set.headSet();
        assertTrue(sm.contains());
        assertTrue(sm.contains());
        assertTrue(sm.contains());
        assertFalse(sm.contains());
        assertFalse(sm.contains());
        Iterator i = sm.iterator();
        Object k;
        k = (Integer)(i.next());
        assertEquals(k);
        k = (Integer)(i.next());
        assertEquals(k);
        k = (Integer)(i.next());
        assertEquals(k);
        assertFalse(i.hasNext());
        sm.clear();
        assertTrue(sm.isEmpty());
        assertEquals(2, set.size());
        assertEquals(set.first());
    }

    
tailSet returns set with keys in requested range
    public void testDescendingTailSetContents() {
        NavigableSet set = dset5();
        SortedSet sm = set.tailSet();
        assertFalse(sm.contains());
        assertTrue(sm.contains());
        assertTrue(sm.contains());
        assertTrue(sm.contains());
        assertTrue(sm.contains());
        Iterator i = sm.iterator();
        Object k;
        k = (Integer)(i.next());
        assertEquals(k);
        k = (Integer)(i.next());
        assertEquals(k);
        k = (Integer)(i.next());
        assertEquals(k);
        k = (Integer)(i.next());
        assertEquals(k);
        assertFalse(i.hasNext());
        SortedSet ssm = sm.tailSet();
        assertEquals(ssm.first());
        assertEquals(ssm.last());
        assertTrue(ssm.remove());
        assertEquals(1, ssm.size());
        assertEquals(3, sm.size());
        assertEquals(4, set.size());
    }