-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackTest.java
More file actions
39 lines (26 loc) · 899 Bytes
/
StackTest.java
File metadata and controls
39 lines (26 loc) · 899 Bytes
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
package Stack.src;
import org.junit.Assert;
import static org.junit.Assert.assertTrue;
public class StackTest {
@org.junit.Test
public void ResizingArrayStackTest() throws Exception {
test(new ArrayStack<>());
}
@org.junit.Test
public void ListStackTest() throws Exception {
test(new ListStack<>());
}
private static void test(MyStack<Integer> stack) throws Exception {
stack.push(1).push(2).push(3).push(4);
Assert.assertEquals(stack.size(), 4);
Assert.assertFalse(stack.isEmpty());
for (Integer item : stack) {
System.out.println(item);
}
Assert.assertEquals(4, (int) stack.pop());
Assert.assertEquals(3, (int) stack.pop());
Assert.assertEquals(2, (int) stack.pop());
Assert.assertEquals(1, (int) stack.pop());
assertTrue(stack.isEmpty());
}
}