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.9 by jsr166, Sat Nov 21 10:29:50 2009 UTC vs.
Revision 1.16 by jsr166, Mon Oct 11 05:40:41 2010 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);
# Line 19 | Line 19 | public class TreeSetTest extends JSR166T
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 212 | Line 208 | public class TreeSetTest extends JSR166T
208              shouldThrow();
209          } catch (NullPointerException success) {}
210      }
211 +
212      /**
213       * addAll of a collection with null elements throws NPE
214       */
# Line 223 | Line 220 | public class TreeSetTest extends JSR166T
220              shouldThrow();
221          } catch (NullPointerException success) {}
222      }
223 +
224      /**
225       * addAll of a collection with any null elements throws NPE after
226       * possibly adding some elements
# Line 259 | Line 257 | public class TreeSetTest extends JSR166T
257      public void testPollFirst() {
258          TreeSet q = populatedSet(SIZE);
259          for (int i = 0; i < SIZE; ++i) {
260 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
260 >            assertEquals(i, q.pollFirst());
261          }
262          assertNull(q.pollFirst());
263      }
# Line 270 | Line 268 | public class TreeSetTest extends JSR166T
268      public void testPollLast() {
269          TreeSet q = populatedSet(SIZE);
270          for (int i = SIZE-1; i >= 0; --i) {
271 <            assertEquals(i, ((Integer)q.pollLast()).intValue());
271 >            assertEquals(i, q.pollLast());
272          }
273          assertNull(q.pollFirst());
274      }
# Line 384 | Line 382 | public class TreeSetTest extends JSR166T
382  
383          Object e4 = q.lower(zero);
384          assertNull(e4);
387
385      }
386  
387      /**
# Line 403 | Line 400 | public class TreeSetTest extends JSR166T
400  
401          Object e4 = q.higher(six);
402          assertNull(e4);
406
403      }
404  
405      /**
# Line 422 | Line 418 | public class TreeSetTest extends JSR166T
418  
419          Object e4 = q.floor(zero);
420          assertNull(e4);
425
421      }
422  
423      /**
# Line 441 | Line 436 | public class TreeSetTest extends JSR166T
436  
437          Object e4 = q.ceiling(six);
438          assertNull(e4);
444
439      }
440  
441      /**
# Line 498 | Line 492 | public class TreeSetTest extends JSR166T
492      /**
493       * iterator.remove removes current element
494       */
495 <    public void testIteratorRemove () {
495 >    public void testIteratorRemove() {
496          final TreeSet q = new TreeSet();
497          q.add(new Integer(2));
498          q.add(new Integer(1));
# Line 669 | Line 663 | public class TreeSetTest extends JSR166T
663      /**
664       * Subsets of subsets subdivide correctly
665       */
666 <    public void testRecursiveSubSets() {
667 <        int setSize = 1000;
666 >    public void testRecursiveSubSets() throws Exception {
667 >        int setSize = expensiveTests ? 1000 : 100;
668          Class cl = TreeSet.class;
669  
670          NavigableSet<Integer> set = newSet(cl);
# Line 688 | Line 682 | public class TreeSetTest extends JSR166T
682                     0, setSize - 1, true);
683      }
684  
685 <    static NavigableSet<Integer> newSet(Class cl) {
686 <        NavigableSet<Integer> result = null;
693 <        try {
694 <            result = (NavigableSet<Integer>) cl.newInstance();
695 <        } catch (Exception e) {
696 <            fail();
697 <        }
685 >    static NavigableSet<Integer> newSet(Class cl) throws Exception {
686 >        NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance();
687          assertEquals(result.size(), 0);
688          assertFalse(result.iterator().hasNext());
689          return result;
# Line 757 | Line 746 | public class TreeSetTest extends JSR166T
746              } else {
747                  try {
748                      set.add(element);
749 <                    fail();
750 <                } catch (IllegalArgumentException e) {
762 <                    // expected
763 <                }
749 >                    shouldThrow();
750 >                } catch (IllegalArgumentException success) {}
751              }
752          }
753      }
# Line 893 | Line 880 | public class TreeSetTest extends JSR166T
880                  // BitSet should support this! Test would run much faster
881                  while (element >= min) {
882                      if (bs.get(element))
883 <                        return(element);
883 >                        return element;
884                      element--;
885                  }
886                  return -1;
# Line 959 | Line 946 | public class TreeSetTest extends JSR166T
946              assertEq(rs.last(),  -1);
947              try {
948                  set.first();
949 <                fail();
950 <            } catch (NoSuchElementException e) {
964 <                // expected
965 <            }
949 >                shouldThrow();
950 >            } catch (NoSuchElementException success) {}
951              try {
952                  set.last();
953 <                fail();
954 <            } catch (NoSuchElementException e) {
970 <                // expected
971 <            }
953 >                shouldThrow();
954 >            } catch (NoSuchElementException success) {}
955          }
956      }
957  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines