KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > co > jezuk > mango > BoundedIteratorTest


1 package uk.co.jezuk.mango;
2
3 import junit.framework.*;
4
5 public class BoundedIteratorTest extends TestCase
6 {
7   java.util.List JavaDoc list;
8
9   public BoundedIteratorTest(String JavaDoc name) { super(name); }
10   public static Test suite() { return new TestSuite(BoundedIteratorTest.class); }
11
12   protected void setUp()
13   {
14     list = new java.util.ArrayList JavaDoc();
15     for(int i = 0; i < 10; ++i)
16       list.add(new Integer JavaDoc(i));
17   } // setUp
18

19   public void test1()
20   {
21     java.util.Iterator JavaDoc bi = Iterators.BoundedIterator(list, 2, 5);
22     assertEquals(true, bi.hasNext());
23     assertEquals(new Integer JavaDoc(2), bi.next());
24     assertEquals(true, bi.hasNext());
25     assertEquals(new Integer JavaDoc(3), bi.next());
26     assertEquals(true, bi.hasNext());
27     assertEquals(new Integer JavaDoc(4), bi.next());
28     assertEquals(false, bi.hasNext());
29   } // test1
30

31   public void test2()
32   {
33     java.util.Iterator JavaDoc bi = Iterators.BoundedIterator(list, 8, 12);
34     assertEquals(true, bi.hasNext());
35     assertEquals(new Integer JavaDoc(8), bi.next());
36     assertEquals(true, bi.hasNext());
37     assertEquals(new Integer JavaDoc(9), bi.next());
38     assertEquals(false, bi.hasNext());
39   } // test2
40

41   public void test3()
42   {
43     java.util.Iterator JavaDoc bi = Iterators.BoundedIterator(list, 12, 12);
44     assertEquals(false, bi.hasNext());
45   } // test3
46

47   public void test4()
48   {
49     java.util.Iterator JavaDoc bi = Iterators.BoundedIterator(list.iterator(), 2, 5);
50     assertEquals(true, bi.hasNext());
51     assertEquals(new Integer JavaDoc(2), bi.next());
52     assertEquals(true, bi.hasNext());
53     assertEquals(new Integer JavaDoc(3), bi.next());
54     assertEquals(true, bi.hasNext());
55     assertEquals(new Integer JavaDoc(4), bi.next());
56     assertEquals(false, bi.hasNext());
57   } // test4
58

59   public void test5()
60   {
61     java.util.Iterator JavaDoc bi = Iterators.BoundedIterator(list.iterator(), 8, 12);
62     assertEquals(true, bi.hasNext());
63     assertEquals(new Integer JavaDoc(8), bi.next());
64     assertEquals(true, bi.hasNext());
65     assertEquals(new Integer JavaDoc(9), bi.next());
66     assertEquals(false, bi.hasNext());
67   } // test5
68

69   public void test6()
70   {
71     java.util.Iterator JavaDoc bi = Iterators.BoundedIterator(list.iterator(), 12, 12);
72     assertEquals(false, bi.hasNext());
73   } // test6
74
} // BoundedIteratorTest
75
Popular Tags