1
2
3
4 package org.melati.poem.util.test;
5
6 import java.util.NoSuchElementException;
7
8 import org.melati.poem.util.IntegerEnumeration;
9
10 import junit.framework.TestCase;
11
12
13
14
15
16
17 public class IntegerEnumerationTest extends TestCase {
18
19
20
21
22 public IntegerEnumerationTest(String name) {
23 super(name);
24 }
25
26
27
28
29
30 protected void setUp() throws Exception {
31 super.setUp();
32 }
33
34
35
36
37
38 protected void tearDown() throws Exception {
39 super.tearDown();
40 }
41
42
43
44
45
46 public void testIntegerEnumerationZeros() {
47 IntegerEnumeration it = new IntegerEnumeration(0,0);
48 int count = 0;
49 while(it.hasMoreElements()) {
50 count++;
51 }
52 assertEquals(0, count);
53 }
54
55
56
57
58 public void testIntegerEnumeration() {
59 IntegerEnumeration it = new IntegerEnumeration(0,1);
60 int count = 0;
61 while(it.hasMoreElements()) {
62 assertEquals(new Integer(0),it.nextElement());
63 count++;
64 }
65 assertEquals(1, count);
66 }
67
68
69
70 public void testIntegerEnumerationMax() {
71 int max = 9;
72 IntegerEnumeration it = new IntegerEnumeration(max - 5, max);
73 int count = 0;
74 while(it.hasMoreElements()) {
75 it.nextElement();
76 count++;
77 }
78 assertEquals(5, count);
79 }
80
81
82
83
84 public void testNextElement() {
85 int max = 9;
86 IntegerEnumeration it = new IntegerEnumeration(max - 5, max);
87 int count = 0;
88 while(it.hasMoreElements()) {
89 it.nextElement();
90 count++;
91 }
92 assertEquals(5, count);
93 try {
94 it.nextElement();
95 fail("Should have blown up");
96 } catch (NoSuchElementException e) {
97 e = null;
98 }
99 }
100
101 }