forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayStackTest.java
More file actions
53 lines (41 loc) · 1.34 KB
/
ArrayStackTest.java
File metadata and controls
53 lines (41 loc) · 1.34 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
package com.examplehub.datastructures.stack;
import static org.junit.jupiter.api.Assertions.*;
import java.util.EmptyStackException;
import org.junit.jupiter.api.Test;
class ArrayStackTest {
@Test
void testArrayStack() {
ArrayStack<String> stack = new ArrayStack<>(5);
assertEquals(stack.size(), 0);
assertTrue(stack.empty());
try {
stack.pop();
fail(); /* this will not happen */
} catch (EmptyStackException e) {
assertTrue(true); /* this will happen */
}
try {
stack.peek();
fail(); /* this will not happen */
} catch (EmptyStackException e) {
assertTrue(true); /* this will happen */
}
assertEquals("Java", stack.push("Java"));
assertEquals("Python", stack.push("Python"));
assertEquals("C", stack.push("C"));
assertEquals("Shell", stack.push("Shell"));
assertEquals("Go", stack.push("Go"));
assertTrue(stack.full());
assertEquals("[Java, Python, C, Shell, Go]", stack.toString());
assertEquals("Go", stack.peek());
assertEquals("Go", stack.pop());
assertEquals("Shell", stack.pop());
assertFalse(stack.empty());
assertEquals(3, stack.size());
assertEquals("[Java, Python, C]", stack.toString());
stack.clear();
assertTrue(stack.empty());
assertEquals(0, stack.size());
assertEquals("[]", stack.toString());
}
}