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

Comparing jsr166/src/test/tck/TreeSetTest.java (file contents):
Revision 1.2 by dl, Wed Apr 19 15:10:54 2006 UTC vs.
Revision 1.6 by jsr166, Mon Nov 16 05:30:08 2009 UTC

# Line 11 | Line 11 | import java.io.*;
11  
12   public class TreeSetTest 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(TreeSetTest.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();
# Line 39 | Line 39 | public class TreeSetTest extends JSR166T
39      private TreeSet populatedSet(int n) {
40          TreeSet q = new TreeSet();
41          assertTrue(q.isEmpty());
42 <        for(int i = n-1; i >= 0; i-=2)
42 >        for (int i = n-1; i >= 0; i-=2)
43              assertTrue(q.add(new Integer(i)));
44 <        for(int i = (n & 1); i < n; i+=2)
44 >        for (int i = (n & 1); i < n; i+=2)
45              assertTrue(q.add(new Integer(i)));
46          assertFalse(q.isEmpty());
47          assertEquals(n, q.size());
# Line 62 | Line 62 | public class TreeSetTest extends JSR166T
62          assertEquals(5, q.size());
63          return q;
64      }
65 <
65 >
66      /**
67       * A new set has unbounded capacity
68       */
# Line 177 | Line 177 | public class TreeSetTest extends JSR166T
177              TreeSet q = populatedSet(SIZE);
178              q.add(null);
179              shouldThrow();
180 <        } catch (NullPointerException success) { }  
180 >        } catch (NullPointerException success) { }
181      }
182  
183      /**
# Line 209 | Line 209 | public class TreeSetTest extends JSR166T
209              q.add(new Object());
210              shouldThrow();
211          }
212 <        catch(ClassCastException success) {}
212 >        catch (ClassCastException success) {}
213      }
214  
215      /**
# Line 306 | Line 306 | public class TreeSetTest extends JSR166T
306          }
307          assertTrue(q.isEmpty());
308      }
309 <        
309 >
310      /**
311       * contains(x) reports true when elements added but not yet removed
312       */
# Line 382 | Line 382 | public class TreeSetTest extends JSR166T
382          }
383      }
384  
385 <    
385 >
386  
387      /**
388       * lower returns preceding element
# Line 467 | Line 467 | public class TreeSetTest extends JSR166T
467          TreeSet q = populatedSet(SIZE);
468          Object[] o = q.toArray();
469          Arrays.sort(o);
470 <        for(int i = 0; i < o.length; i++)
470 >        for (int i = 0; i < o.length; i++)
471              assertEquals(o[i], q.pollFirst());
472      }
473  
# Line 479 | Line 479 | public class TreeSetTest extends JSR166T
479          Integer[] ints = new Integer[SIZE];
480          ints = (Integer[])q.toArray(ints);
481          Arrays.sort(ints);
482 <        for(int i = 0; i < ints.length; i++)
482 >        for (int i = 0; i < ints.length; i++)
483              assertEquals(ints[i], q.pollFirst());
484      }
485 <    
485 >
486      /**
487       * iterator iterates through all elements
488       */
# Line 490 | Line 490 | public class TreeSetTest extends JSR166T
490          TreeSet q = populatedSet(SIZE);
491          int i = 0;
492          Iterator it = q.iterator();
493 <        while(it.hasNext()) {
493 >        while (it.hasNext()) {
494              assertTrue(q.contains(it.next()));
495              ++i;
496          }
# Line 504 | Line 504 | public class TreeSetTest extends JSR166T
504          TreeSet q = new TreeSet();
505          int i = 0;
506          Iterator it = q.iterator();
507 <        while(it.hasNext()) {
507 >        while (it.hasNext()) {
508              assertTrue(q.contains(it.next()));
509              ++i;
510          }
# Line 540 | Line 540 | public class TreeSetTest extends JSR166T
540          for (int i = 0; i < SIZE; ++i) {
541              assertTrue(s.indexOf(String.valueOf(i)) >= 0);
542          }
543 <    }        
543 >    }
544  
545      /**
546 <     * A deserialized serialized set has same elements
546 >     * A deserialized serialized set has same elements
547       */
548      public void testSerialization() {
549          TreeSet q = populatedSet(SIZE);
# Line 557 | Line 557 | public class TreeSetTest extends JSR166T
557              ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
558              TreeSet r = (TreeSet)in.readObject();
559              assertEquals(q.size(), r.size());
560 <            while (!q.isEmpty())
560 >            while (!q.isEmpty())
561                  assertEquals(q.pollFirst(), r.pollFirst());
562 <        } catch(Exception e){
562 >        } catch (Exception e) {
563              e.printStackTrace();
564              unexpectedException();
565          }
# Line 705 | Line 705 | public class TreeSetTest extends JSR166T
705          check(set,                 0, setSize - 1, true);
706          check(set.descendingSet(), 0, setSize - 1, false);
707  
708 <        bashSubSet(set.navigableSubSet(0, true, setSize, false),
708 >        bashSubSet(set.subSet(0, true, setSize, false),
709                     0, setSize - 1, true);
710      }
711  
# Line 713 | Line 713 | public class TreeSetTest extends JSR166T
713          NavigableSet<Integer> result = null;
714          try {
715              result = (NavigableSet<Integer>) cl.newInstance();
716 <        } catch(Exception e) {
716 >        } catch (Exception e) {
717              fail();
718          }
719          assertEquals(result.size(), 0);
# Line 738 | Line 738 | public class TreeSetTest extends JSR166T
738          }
739  
740          // Remove a bunch of entries with iterator
741 <        for(Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
741 >        for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
742              if (rnd.nextBoolean()) {
743                  bs.clear(it.next());
744                  it.remove();
# Line 763 | Line 763 | public class TreeSetTest extends JSR166T
763          }
764  
765          // Remove a bunch of entries with iterator
766 <        for(Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
766 >        for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
767              if (rnd.nextBoolean()) {
768                  bs.clear(it.next());
769                  it.remove();
# Line 779 | Line 779 | public class TreeSetTest extends JSR166T
779                  try {
780                      set.add(element);
781                      fail();
782 <                } catch(IllegalArgumentException e) {
782 >                } catch (IllegalArgumentException e) {
783                      // expected
784                  }
785              }
# Line 812 | Line 812 | public class TreeSetTest extends JSR166T
812  
813          // headSet - pick direction and endpoint inclusion randomly
814          boolean incl = rnd.nextBoolean();
815 <        NavigableSet<Integer> hm = set.navigableHeadSet(midPoint, incl);
815 >        NavigableSet<Integer> hm = set.headSet(midPoint, incl);
816          if (ascending) {
817              if (rnd.nextBoolean())
818                  bashSubSet(hm, min, midPoint - (incl ? 0 : 1), true);
# Line 829 | Line 829 | public class TreeSetTest extends JSR166T
829  
830          // tailSet - pick direction and endpoint inclusion randomly
831          incl = rnd.nextBoolean();
832 <        NavigableSet<Integer> tm = set.navigableTailSet(midPoint,incl);
832 >        NavigableSet<Integer> tm = set.tailSet(midPoint,incl);
833          if (ascending) {
834              if (rnd.nextBoolean())
835                  bashSubSet(tm, midPoint + (incl ? 0 : 1), max, true);
# Line 854 | Line 854 | public class TreeSetTest extends JSR166T
854          boolean lowIncl = rnd.nextBoolean();
855          boolean highIncl = rnd.nextBoolean();
856          if (ascending) {
857 <            NavigableSet<Integer> sm = set.navigableSubSet(
857 >            NavigableSet<Integer> sm = set.subSet(
858                  endpoints[0], lowIncl, endpoints[1], highIncl);
859              if (rnd.nextBoolean())
860                  bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1),
# Line 863 | Line 863 | public class TreeSetTest extends JSR166T
863                  bashSubSet(sm.descendingSet(), endpoints[0] + (lowIncl ? 0 : 1),
864                             endpoints[1] - (highIncl ? 0 : 1), false);
865          } else {
866 <            NavigableSet<Integer> sm = set.navigableSubSet(
866 >            NavigableSet<Integer> sm = set.subSet(
867                  endpoints[1], highIncl, endpoints[0], lowIncl);
868              if (rnd.nextBoolean())
869                  bashSubSet(sm, endpoints[0] + (lowIncl ? 0 : 1),
# Line 981 | Line 981 | public class TreeSetTest extends JSR166T
981              try {
982                  set.first();
983                  fail();
984 <            } catch(NoSuchElementException e) {
984 >            } catch (NoSuchElementException e) {
985                  // expected
986              }
987              try {
988                  set.last();
989                  fail();
990 <            } catch(NoSuchElementException e) {
990 >            } catch (NoSuchElementException e) {
991                  // expected
992              }
993          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines