-
Notifications
You must be signed in to change notification settings - Fork 19.4k
/
StackUsingTwoQueuesTest.java
70 lines (59 loc) · 1.6 KB
/
StackUsingTwoQueuesTest.java
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
package com.thealgorithms.stacks;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class StackUsingTwoQueuesTest {
private StackUsingTwoQueues stack;
@BeforeEach
public void setUp() {
stack = new StackUsingTwoQueues();
}
@Test
public void testPushAndPeek() {
stack.push(1);
stack.push(2);
stack.push(3);
assertEquals(3, stack.peek());
}
@Test
public void testPop() {
stack.push(1);
stack.push(2);
stack.push(3);
assertEquals(3, stack.pop());
assertEquals(2, stack.pop());
assertEquals(1, stack.pop());
}
@Test
public void testPeek() {
stack.push(10);
stack.push(20);
assertEquals(20, stack.peek());
stack.pop();
assertEquals(10, stack.peek());
}
@Test
public void testIsEmpty() {
assertTrue(stack.isEmpty());
stack.push(1);
assertFalse(stack.isEmpty());
stack.pop();
assertTrue(stack.isEmpty());
}
@Test
public void testSize() {
assertEquals(0, stack.size());
stack.push(1);
stack.push(2);
assertEquals(2, stack.size());
stack.pop();
assertEquals(1, stack.size());
}
@Test
public void testPeekEmptyStack() {
assertNull(stack.peek());
}
}