KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > ristretto > imap > SequenceSetTest


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Ristretto Mail API.
15  *
16  * The Initial Developers of the Original Code are
17  * Timo Stich and Frederik Dietz.
18  * Portions created by the Initial Developers are Copyright (C) 2004
19  * All Rights Reserved.
20  *
21  * Contributor(s):
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by deleting the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not delete
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35  * ***** END LICENSE BLOCK ***** */

36 package org.columba.ristretto.imap;
37
38 import junit.framework.TestCase;
39 import junitx.framework.ArrayAssert;
40
41 public class SequenceSetTest extends TestCase {
42     
43     public void testAll1() {
44         SequenceSet s = new SequenceSet();
45         s.addAll();
46         s.addAll();
47         
48         assertEquals("1:*", s.toString());
49         
50         ArrayAssert.assertEquals(new int[] {1,2,3}, s.toArray(3) );
51     }
52     
53     public void testAll2() {
54         SequenceSet s = new SequenceSet();
55         s.addAll();
56         s.add(100);
57         
58         assertEquals("1:*", s.toString());
59     }
60
61     public void testAll3() {
62         SequenceSet s = new SequenceSet();
63         s.addAll();
64         s.add(100,200);
65         
66         assertEquals("1:*", s.toString());
67     }
68
69     public void testAll6() {
70         SequenceSet s = new SequenceSet();
71         s.add(1,100);
72         s.add(100,SequenceEntry.STAR);
73         
74         assertEquals("1:*", s.toString());
75     }
76
77     public void testAll7() {
78         SequenceSet s = new SequenceSet();
79         s.add(1,100);
80         s.add(500);
81         s.add(100, SequenceEntry.STAR);
82         
83         assertEquals("1:*", s.toString());
84     }
85
86     public void testAll8() {
87         SequenceSet s = new SequenceSet();
88         s.add(1,10);
89         s.add(100, SequenceEntry.STAR);
90         
91         assertEquals("1:10,100:*", s.toString());
92         ArrayAssert.assertEquals(new int[] {1,2,3,4,5,6,7,8,9,10,100,101,102}, s.toArray(102));
93     }
94     
95     public void testOpenRange1() {
96         SequenceSet s = new SequenceSet();
97         s.add(1,10);
98         s.add(100);
99         
100         assertEquals("1:10,100", s.toString());
101         
102         ArrayAssert.assertEquals(new int[] {1,2,3,4,5,6,7,8,9,10,100}, s.toArray(13));
103     }
104
105     public void testOpenRange2() {
106         SequenceSet s = new SequenceSet();
107         s.add(10,1);
108         s.add(8);
109         
110         assertEquals("1:10", s.toString());
111         ArrayAssert.assertEquals(new int[] {1,2,3,4,5,6,7,8,9,10}, s.toArray(13));
112     }
113
114     public void testOpenRange3() {
115         SequenceSet s = new SequenceSet();
116         s.add(1,10);
117         s.add(8,10);
118         
119         assertEquals("1:10", s.toString());
120         ArrayAssert.assertEquals(new int[] {1,2,3,4,5,6,7,8,9,10}, s.toArray(13));
121         
122     }
123
124     public void testOpenRange4() {
125         SequenceSet s = new SequenceSet();
126         s.add(10, SequenceEntry.STAR);
127         s.add(8,9);
128         
129         assertEquals("8:*", s.toString());
130         ArrayAssert.assertEquals(new int[] {8,9,10,11,12,13}, s.toArray(13));
131     }
132     
133     public void testOpenRange5() {
134         SequenceSet s = new SequenceSet();
135         s.add(SequenceEntry.STAR,10);
136         s.add(8);
137         
138         assertEquals("8,10:*", s.toString());
139         ArrayAssert.assertEquals(new int[] {8,10,11,12,13}, s.toArray(13));
140     }
141
142     public void testRange1() {
143         SequenceSet s = new SequenceSet();
144         s.add(10,9);
145         s.add(5,8);
146         
147         assertEquals("5:10", s.toString());
148         ArrayAssert.assertEquals(new int[] {5,6,7,8,9,10}, s.toArray(13));
149     }
150     
151     public void testRange2() {
152         SequenceSet s = new SequenceSet();
153         s.add(5,10);
154         s.add(5,10);
155         
156         assertEquals("5:10", s.toString());
157         ArrayAssert.assertEquals(new int[] {5,6,7,8,9,10}, s.toArray(13));
158     }
159
160     public void testRange3() {
161         SequenceSet s = new SequenceSet();
162         s.add(7);
163         s.add(5);
164         s.add(10);
165         s.add(6);
166         
167         assertEquals("5:7,10", s.toString());
168         ArrayAssert.assertEquals(new int[] {5,6,7,10}, s.toArray(13));
169     }
170
171     public void testRange4() {
172         SequenceSet s = new SequenceSet();
173         s.add(7);
174         s.add(5,10);
175         s.add(10);
176         s.add(6);
177         
178         assertEquals("5:10", s.toString());
179         ArrayAssert.assertEquals(new int[] {5,6,7,8,9,10}, s.toArray(13));
180     }
181     
182     public void testRange5() {
183         SequenceSet s = new SequenceSet();
184         s.add(3,10);
185         s.add(10);
186         s.add(2,20);
187         s.add(5,100);
188         
189         assertEquals("2:100", s.toString());
190     }
191
192
193     public void testSingle1() {
194         SequenceSet s = new SequenceSet();
195         s.add(1);
196         s.add(SequenceEntry.STAR);
197         
198         assertEquals("1,*", s.toString());
199         ArrayAssert.assertEquals(new int[] {1,13}, s.toArray(13));
200     }
201     
202     public void testSingle2() {
203         SequenceSet s = new SequenceSet();
204         s.add(1);
205         s.add(2,5);
206         s.add(6);
207         
208         assertEquals("1:6", s.toString());
209         ArrayAssert.assertEquals(new int[] {1,2,3,4,5,6}, s.toArray(13));
210     }
211     
212     public void testConstructor() {
213         int[] test = new int[] {1,2,3,4,5,6,7,8,9,10};
214         SequenceSet s = new SequenceSet(test,0,4);
215         assertEquals("1:4", s.toString());
216         
217         s = new SequenceSet(test,4,4);
218         assertEquals("5:8", s.toString());
219
220         s = new SequenceSet(test,8,2);
221         assertEquals("9:10", s.toString());
222     }
223 }
224
Popular Tags