forked from john-bai/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIteratorTest.java
More file actions
131 lines (116 loc) · 2.66 KB
/
Copy pathIteratorTest.java
File metadata and controls
131 lines (116 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package designpatterns;
import java.util.List;
import java.util.ArrayList;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author jtherrell
*/
public class IteratorTest {
private List<String> list;
private Iterator<String> iterator;
public IteratorTest() {
list = new ArrayList<String>();
list.add("The");
list.add("official");
list.add("Iterator");
list.add("test!");
iterator = new Iterator<String>(list);
}
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
/**
* Test of isEmpty method, of class Iterator.
*/ @Test
public void testIsEmptyTrue() {
while (0 < list.size())
list.remove(0);
boolean expResult = true;
boolean result = iterator.isEmpty();
assertEquals(expResult, result);
}
/**
* Test of isEmpty method, of class Iterator.
*/ @Test
public void testIsEmptyFalse() {
boolean expResult = false;
boolean result = iterator.isEmpty();
assertEquals(expResult, result);
}
/**
* Test of hasNext method, of class Iterator.
*/ @Test
public void testHasNextTrue() {
boolean expResult = true;
boolean result = iterator.hasNext();
assertEquals(expResult, result);
}
/**
* Test of hasNext method, of class Iterator.
*/ @Test
public void testHasNextFalse() {
boolean expResult = false;
iterator.next();
iterator.next();
iterator.next();
iterator.next();
boolean result = iterator.hasNext();
assertEquals(expResult, result);
}
/**
* Test of hasPrevious method, of class Iterator.
*/ @Test
public void testHasPrevTrue() {
iterator.next();
boolean expResult = true;
boolean result = iterator.hasPrev();
assertEquals(expResult, result);
}
/**
* Test of hasPrevious method, of class Iterator.
*/ @Test
public void testHasPrevFalse() {
boolean expResult = false;
boolean result = iterator.hasPrev();
assertEquals(expResult, result);
}
/**
* Test of next method, of class Iterator.
*/ @Test
public void testNext() {
int i = 0;
while(iterator.hasNext()) {
String expResult = list.get(i);
String result = iterator.next();
assertEquals(expResult, result);
i++;
}
}
/**
* Test of next method, of class Iterator.
*/ @Test
public void testPrev() {
iterator.next();
iterator.next();
iterator.next();
iterator.next();
int i = list.size() - 1;
while(iterator.hasPrev()) {
String expResult = list.get(i);
String result = iterator.prev();
assertEquals(expResult, result);
i--;
}
}
}