forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackExampleTest.java
More file actions
44 lines (39 loc) · 1.02 KB
/
StackExampleTest.java
File metadata and controls
44 lines (39 loc) · 1.02 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
package com.examplehub.basics.queue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayDeque;
import java.util.Deque;
import org.junit.jupiter.api.Test;
class StackExampleTest {
@Test
void testPush() {
Deque<String> stack = new ArrayDeque<>();
stack.push("A");
stack.push("B");
stack.push("C");
stack.push("D");
assertEquals("[D, C, B, A]", stack.toString());
}
@Test
void testPeek() {
Deque<String> stack = new ArrayDeque<>();
stack.push("A");
stack.push("B");
stack.push("C");
stack.push("D");
assertEquals("[D, C, B, A]", stack.toString());
assertEquals("D", stack.peek());
}
@Test
void testPop() {
Deque<String> stack = new ArrayDeque<>();
stack.push("A");
stack.push("B");
stack.push("C");
stack.push("D");
assertEquals("[D, C, B, A]", stack.toString());
assertEquals("D", stack.pop());
assertEquals("C", stack.pop());
assertEquals("B", stack.pop());
assertEquals("A", stack.peek());
}
}