forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedStackTest.java
More file actions
48 lines (38 loc) · 1.19 KB
/
LinkedStackTest.java
File metadata and controls
48 lines (38 loc) · 1.19 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
package com.examplehub.datastructures.stack;
import static org.junit.jupiter.api.Assertions.*;
import java.util.EmptyStackException;
import org.junit.jupiter.api.Test;
class LinkedStackTest {
@Test
void test() {
LinkedStack<String> stack = new LinkedStack<>();
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 */
}
assertTrue(stack.push("Java"));
assertTrue(stack.push("Python"));
assertTrue(stack.push("C"));
assertTrue(stack.push("Shell"));
assertTrue(stack.push("Go"));
assertEquals("[Go, Shell, C, Python, Java]", stack.toString());
assertEquals("Go", stack.peek());
assertEquals("Go", stack.pop());
assertEquals("Shell", stack.pop());
assertFalse(stack.empty());
assertEquals(3, stack.size());
assertEquals("[C, Python, Java]", stack.toString());
stack.clear();
assertTrue(stack.empty());
assertEquals(0, stack.size());
assertEquals("[]", stack.toString());
}
}