KickJava   Java API By Example, From Geeks To Geeks.

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


1 package uk.co.jezuk.mango;
2
3 import junit.framework.*;
4
5 import java.util.List JavaDoc;
6 import java.util.ArrayList JavaDoc;
7
8 public class IntersectionTest extends TestCase
9 {
10     public IntersectionTest(String JavaDoc name) { super(name); }
11     public static Test suite() { return new TestSuite(IntersectionTest.class); }
12
13     public void test1()
14     {
15         List JavaDoc l1 = new java.util.ArrayList JavaDoc();
16         Algorithms.intersection(l1, l1, l1);
17
18         assertEquals(0, l1.size());
19     } // test1
20

21     public void test2()
22     {
23         List JavaDoc l1 = new java.util.ArrayList JavaDoc();
24         l1.add("1");
25         l1.add("2");
26         l1.add("3");
27         List JavaDoc i = new java.util.ArrayList JavaDoc();
28         Algorithms.intersection(l1, l1, i);
29         
30         assertEquals(3, i.size());
31         assertEquals("1", i.get(0));
32         assertEquals("2", i.get(1));
33         assertEquals("3", i.get(2));
34     } // test2
35

36     public void test3()
37     {
38         List JavaDoc l1 = new java.util.ArrayList JavaDoc();
39         l1.add("1");
40         l1.add("2");
41         l1.add("3");
42         List JavaDoc l2 = new java.util.ArrayList JavaDoc();
43         l2.add("1");
44         l2.add("2");
45         l2.add("3");
46         List JavaDoc i = new java.util.ArrayList JavaDoc();
47         Algorithms.intersection(l1, l2, i);
48         
49         assertEquals(3, i.size());
50         assertEquals("1", i.get(0));
51         assertEquals("2", i.get(1));
52         assertEquals("3", i.get(2));
53     } // test3
54

55     public void test4()
56     {
57         List JavaDoc l1 = new java.util.ArrayList JavaDoc();
58         l1.add("1");
59         l1.add("2");
60         l1.add("3");
61         List JavaDoc l2 = new java.util.ArrayList JavaDoc();
62         l2.add("1");
63         l2.add("3");
64         List JavaDoc i = new java.util.ArrayList JavaDoc();
65         Algorithms.intersection(l1, l2, i);
66         
67         assertEquals(2, i.size());
68         assertEquals("1", i.get(0));
69         assertEquals("3", i.get(1));
70     } // test4
71

72     public void test5()
73     {
74         List JavaDoc l1 = new java.util.ArrayList JavaDoc();
75         l1.add("1");
76         l1.add("2");
77         l1.add("3");
78         List JavaDoc l2 = new java.util.ArrayList JavaDoc();
79         l2.add("2");
80         List JavaDoc i = new java.util.ArrayList JavaDoc();
81         Algorithms.intersection(l1, l2, i);
82         
83         assertEquals(1, i.size());
84         assertEquals("2", i.get(0));
85     } // test5
86

87     public void test6()
88     {
89         List JavaDoc l1 = new java.util.ArrayList JavaDoc();
90         l1.add("1");
91         l1.add("2");
92         l1.add("3");
93         List JavaDoc l2 = new java.util.ArrayList JavaDoc();
94         l2.add("2");
95         l2.add("1");
96         List JavaDoc i = new java.util.ArrayList JavaDoc();
97         Algorithms.intersection(l1, l2, i);
98         
99         assertEquals(2, i.size());
100         assertEquals("1", i.get(0));
101         assertEquals("2", i.get(1));
102     } // test6
103

104     public void test7()
105     {
106         List JavaDoc l1 = new java.util.ArrayList JavaDoc();
107         l1.add("1");
108         l1.add("3");
109         List JavaDoc l2 = new java.util.ArrayList JavaDoc();
110         l2.add("1");
111         l2.add("2");
112         l2.add("3");
113         List JavaDoc i = new java.util.ArrayList JavaDoc();
114         Algorithms.intersection(l1, l2, i);
115         
116         assertEquals(2, i.size());
117         assertEquals("1", i.get(0));
118         assertEquals("3", i.get(1));
119     } // test7
120

121     public void test8()
122     {
123         List JavaDoc l1 = new java.util.ArrayList JavaDoc();
124         l1.add("2");
125         List JavaDoc l2 = new java.util.ArrayList JavaDoc();
126         l2.add("1");
127         l2.add("2");
128         l2.add("3");
129         List JavaDoc i = new java.util.ArrayList JavaDoc();
130         Algorithms.intersection(l1, l2, i);
131         
132         assertEquals(1, i.size());
133         assertEquals("2", i.get(0));
134     } // test8
135

136     public void test9()
137     {
138         List JavaDoc l1 = new java.util.ArrayList JavaDoc();
139         l1.add("1");
140         l1.add("2");
141         l1.add("3");
142         List JavaDoc l2 = new java.util.ArrayList JavaDoc();
143         l2.add("4");
144         l2.add("5");
145         l2.add("6");
146         List JavaDoc i = new java.util.ArrayList JavaDoc();
147         Algorithms.intersection(l1, l2, i);
148         
149         assertEquals(0, i.size());
150     } // test9
151
} // class IntersectionTest
152
Popular Tags