KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sablecc > sablecc > alphabet > AdjacencyRealmTest


1 /* This file is part of SableCC ( http://sablecc.org ).
2  *
3  * Copyright 2007 Patrick Pelletier <pp.pelletier@gmail.com>
4  * Copyright 2007 Etienne M. Gagnon <egagnon@j-meg.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.sablecc.sablecc.alphabet;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.fail;
23
24 import java.math.BigInteger JavaDoc;
25
26 import org.junit.Test;
27 import org.sablecc.sablecc.exception.InternalException;
28
29 public class AdjacencyRealmTest {
30
31     // Initiating global interval variables for the 3 types
32
private Interval<Integer JavaDoc> intervalInteger;
33
34     private Interval<BigInteger JavaDoc> intervalBigInt;
35
36     @Test
37     public void testMin() {
38
39         // =========================================
40
// Testing with Integer
41
// =========================================
42

43         Integer JavaDoc intBound1;
44         Integer JavaDoc intBound2;
45
46         // Test when bound1 is null
47
intBound1 = null;
48         intBound2 = 0;
49         try {
50             AdjacencyRealm.min(intBound1, intBound2);
51             fail("An InternalException should be thrown for a null bound.");
52
53         }
54         catch (InternalException e) {
55             // Expected
56
}
57
58         // Test when bound2 is null
59
intBound1 = 0;
60         intBound2 = null;
61         try {
62             AdjacencyRealm.min(intBound1, intBound2);
63             fail("An InternalException should be thrown for a null bound.");
64
65         }
66         catch (InternalException e) {
67             // Expected
68
}
69
70         // Test when bound1 and bound2 are null
71
intBound1 = null;
72         intBound2 = null;
73         try {
74             AdjacencyRealm.min(intBound1, intBound2);
75             fail("An InternalException should be thrown for a null bound.");
76
77         }
78         catch (InternalException e) {
79             // Expected
80
}
81
82         // Test when bound1 > bound2
83
intBound1 = 10;
84         intBound2 = 1;
85         try {
86             assertEquals("bound2 not returned when bound1 > bound2", intBound2,
87                     AdjacencyRealm.min(intBound1, intBound2));
88         }
89         catch (InternalException e) {
90             fail("An InternalException should not be thrown for non-null bounds.");
91         }
92
93         // Test when bound1 < bound2
94
intBound1 = 1;
95         intBound2 = 10;
96         try {
97             assertEquals("bound1 not returned when bound1 < bound2", intBound1,
98                     AdjacencyRealm.min(intBound1, intBound2));
99         }
100         catch (InternalException e) {
101             fail("An InternalException should not be thrown for non-null bounds.");
102         }
103
104         // Test when bound1 = bound2
105
intBound1 = 10;
106         intBound2 = 10;
107         try {
108             assertEquals("bound2 not returned when bound1 = bound2", intBound2,
109                     AdjacencyRealm.min(intBound1, intBound2));
110         }
111         catch (InternalException e) {
112             fail("An InternalException should not be thrown for non-null bounds.");
113         }
114
115         // =========================================
116
// Testing with String
117
// =========================================
118

119         String JavaDoc stringBound1;
120         String JavaDoc stringBound2;
121
122         // Test when bound1 is null
123
stringBound1 = null;
124         stringBound2 = "aaa";
125         try {
126             AdjacencyRealm.min(stringBound1, stringBound2);
127             fail("An InternalException should be thrown for a null bound.");
128
129         }
130         catch (InternalException e) {
131             // Expected
132
}
133
134         // Test when bound2 is null
135
stringBound1 = "aaa";
136         stringBound2 = null;
137         try {
138             AdjacencyRealm.min(stringBound1, stringBound2);
139             fail("An InternalException should be thrown for a null bound.");
140
141         }
142         catch (InternalException e) {
143             // Expected
144
}
145
146         // Test when bound1 and bound2 are null
147
stringBound1 = null;
148         stringBound2 = null;
149         try {
150             AdjacencyRealm.min(stringBound1, stringBound2);
151             fail("An InternalException should be thrown for a null bound.");
152
153         }
154         catch (InternalException e) {
155             // Expected
156
}
157
158         // Test when bound1 > bound2
159
stringBound1 = "ccc";
160         stringBound2 = "aaa";
161         try {
162             assertEquals("bound2 not returned when bound1 > bound2",
163                     stringBound2, AdjacencyRealm
164                             .min(stringBound1, stringBound2));
165         }
166         catch (InternalException e) {
167             fail("An InternalException should not be thrown for non-null bounds.");
168         }
169
170         // Test when bound1 < bound2
171
stringBound1 = "aaa";
172         stringBound2 = "ccc";
173         try {
174             assertEquals("bound1 not returned when bound1 < bound2",
175                     stringBound1, AdjacencyRealm
176                             .min(stringBound1, stringBound2));
177         }
178         catch (InternalException e) {
179             fail("An InternalException should not be thrown for non-null bounds.");
180         }
181
182         // Test when bound1 = bound2
183
stringBound1 = "ccc";
184         stringBound2 = "ccc";
185         try {
186             assertEquals("bound2 not returned when bound1 = bound2",
187                     stringBound2, AdjacencyRealm
188                             .min(stringBound1, stringBound2));
189         }
190         catch (InternalException e) {
191             fail("An InternalException should not be thrown for non-null bounds.");
192         }
193
194     }
195
196     @Test
197     public void testMax() {
198
199         // =========================================
200
// Testing with Integer
201
// =========================================
202

203         Integer JavaDoc intBound1;
204         Integer JavaDoc intBound2;
205
206         // Test when bound1 is null
207
intBound1 = null;
208         intBound2 = 0;
209         try {
210             AdjacencyRealm.max(intBound1, intBound2);
211             fail("An InternalException should be thrown for a null bound.");
212
213         }
214         catch (InternalException e) {
215             // Expected
216
}
217
218         // Test when bound2 is null
219
intBound1 = 0;
220         intBound2 = null;
221         try {
222             AdjacencyRealm.max(intBound1, intBound2);
223             fail("An InternalException should be thrown for a null bound.");
224
225         }
226         catch (InternalException e) {
227             // Expected
228
}
229
230         // Test when bound1 and bound2 are null
231
intBound1 = null;
232         intBound2 = null;
233         try {
234             AdjacencyRealm.max(intBound1, intBound2);
235             fail("An InternalException should be thrown for a null bound.");
236
237         }
238         catch (InternalException e) {
239             // Expected
240
}
241
242         // Test when bound1 > bound2
243
intBound1 = 10;
244         intBound2 = 1;
245         try {
246             assertEquals("bound1 not returned when bound1 > bound2", intBound1,
247                     AdjacencyRealm.max(intBound1, intBound2));
248         }
249         catch (InternalException e) {
250             fail("An InternalException should not be thrown for non-null bounds.");
251         }
252
253         // Test when bound1 < bound2
254
intBound1 = 1;
255         intBound2 = 10;
256         try {
257             assertEquals("bound2 not returned when bound1 < bound2", intBound2,
258                     AdjacencyRealm.max(intBound1, intBound2));
259         }
260         catch (InternalException e) {
261             fail("An InternalException should not be thrown for non-null bounds.");
262         }
263
264         // Test when bound1 = bound2
265
intBound1 = 10;
266         intBound2 = 10;
267         try {
268             assertEquals("bound2 not returned when bound1 = bound2", intBound2,
269                     AdjacencyRealm.max(intBound1, intBound2));
270         }
271         catch (InternalException e) {
272             fail("An InternalException should not be thrown for non-null bounds.");
273         }
274
275         // =========================================
276
// Testing with String
277
// =========================================
278

279         String JavaDoc stringBound1;
280         String JavaDoc stringBound2;
281
282         // Test when bound1 is null
283
stringBound1 = null;
284         stringBound2 = "aaa";
285         try {
286             AdjacencyRealm.max(stringBound1, stringBound2);
287             fail("An InternalException should be thrown for a null bound.");
288
289         }
290         catch (InternalException e) {
291             // Expected
292
}
293
294         // Test when bound2 is null
295
stringBound1 = "aaa";
296         stringBound2 = null;
297         try {
298             AdjacencyRealm.max(stringBound1, stringBound2);
299             fail("An InternalException should be thrown for a null bound.");
300
301         }
302         catch (InternalException e) {
303             // Expected
304
}
305
306         // Test when bound1 and bound2 are null
307
stringBound1 = null;
308         stringBound2 = null;
309         try {
310             AdjacencyRealm.max(stringBound1, stringBound2);
311             fail("An InternalException should be thrown for a null bound.");
312
313         }
314         catch (InternalException e) {
315             // Expected
316
}
317
318         // Test when bound1 > bound2
319
stringBound1 = "ccc";
320         stringBound2 = "aaa";
321         try {
322             assertEquals("bound1 not returned when bound1 > bound2",
323                     stringBound1, AdjacencyRealm
324                             .max(stringBound1, stringBound2));
325         }
326         catch (InternalException e) {
327             fail("An InternalException should not be thrown for non-null bounds.");
328         }
329
330         // Test when bound1 < bound2
331
stringBound1 = "aaa";
332         stringBound2 = "ccc";
333         try {
334             assertEquals("bound2 not returned when bound1 < bound2",
335                     stringBound2, AdjacencyRealm
336                             .max(stringBound1, stringBound2));
337         }
338         catch (InternalException e) {
339             fail("An InternalException should not be thrown for non-null bounds.");
340         }
341
342         // Test when bound1 = bound2
343
stringBound1 = "ccc";
344         stringBound2 = "ccc";
345         try {
346             assertEquals("bound2 not returned when bound1 = bound2",
347                     stringBound2, AdjacencyRealm
348                             .max(stringBound1, stringBound2));
349         }
350         catch (InternalException e) {
351             fail("An InternalException should not be thrown for non-null bounds.");
352         }
353
354     }
355
356     @Test
357     public void testCreateIntervalTT() {
358
359         // Testing createInterval(T, T) with type Integer
360
this.intervalInteger = new Interval<Integer JavaDoc>(0, 10, Realms.getInteger());
361         Interval<Integer JavaDoc> createdIntervalInt = Realms.getInteger()
362                 .createInterval(0, 10);
363         assertEquals(
364                 "Created interval with integer (2 bounds) not the same as expected",
365                 this.intervalInteger, createdIntervalInt);
366
367         // Testing createInterval(T, T) with type BigInteger
368
this.intervalBigInt = new Interval<BigInteger JavaDoc>(new BigInteger JavaDoc("1000"),
369                 new BigInteger JavaDoc("100000"), Realms.getBigInteger());
370         Interval<BigInteger JavaDoc> createdIntervalBigInt = Realms.getBigInteger()
371                 .createInterval(new BigInteger JavaDoc("1000"),
372                         new BigInteger JavaDoc("100000"));
373         assertEquals(
374                 "Created interval with big integer (2 bounds) not the same as expected",
375                 this.intervalBigInt, createdIntervalBigInt);
376     }
377
378     @Test
379     public void testCreateIntervalT() {
380
381         // Testing createInterval(T) with type Integer
382
this.intervalInteger = new Interval<Integer JavaDoc>(10, Realms.getInteger());
383         Interval<Integer JavaDoc> createdIntervalInt = Realms.getInteger()
384                 .createInterval(10);
385         assertEquals(
386                 "Created interval with integer (1 bound) not the same as expected",
387                 this.intervalInteger, createdIntervalInt);
388
389         // Testing createInterval(T) with type BigInteger
390
this.intervalBigInt = new Interval<BigInteger JavaDoc>(
391                 new BigInteger JavaDoc("100000"), Realms.getBigInteger());
392         Interval<BigInteger JavaDoc> createdIntervalBigInt = Realms.getBigInteger()
393                 .createInterval(new BigInteger JavaDoc("100000"));
394         assertEquals(
395                 "Created interval with big integer (1 bound) not the same as expected",
396                 this.intervalBigInt, createdIntervalBigInt);
397
398     }
399
400 }
401
Popular Tags