forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoStackTest.java
More file actions
81 lines (67 loc) · 1.82 KB
/
TwoStackTest.java
File metadata and controls
81 lines (67 loc) · 1.82 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.examplehub.datastructures.stack;
import static org.junit.jupiter.api.Assertions.*;
import java.util.EmptyStackException;
import org.junit.jupiter.api.Test;
class TwoStackTest {
@Test
void testTwoStack() {
TwoStack<Integer> stack = new TwoStack<>(7);
assertTrue(stack.empty());
assertEquals(0, stack.size());
try {
stack.pop1();
fail(); /* this should will not happen */
} catch (EmptyStackException e) {
assertTrue(true); /* this should will happen */
}
try {
stack.pop2();
fail(); /* this should will not happen */
} catch (EmptyStackException e) {
assertTrue(true); /* this should will happen */
}
for (int i = 1; i <= 7; i++) {
if (i % 2 == 0) {
stack.push1(i);
} else {
stack.push2(i);
}
}
assertTrue(stack.full());
assertEquals(7, stack.size());
try {
stack.push1(666);
fail(); /* this should will not happen */
} catch (EmptyStackException e) {
assertTrue(true); /* this should will happen */
}
try {
stack.push2(666);
fail(); /* this should will not happen */
} catch (EmptyStackException e) {
assertTrue(true); /* this should will happen */
}
assertEquals(6, stack.pop1());
assertEquals(4, stack.pop1());
assertEquals(2, stack.pop1());
assertEquals(7, stack.pop2());
assertEquals(5, stack.pop2());
assertEquals(3, stack.pop2());
assertEquals(1, stack.pop2());
assertEquals(0, stack.size());
assertTrue(stack.empty());
}
@Test
void testClear() {
TwoStack<String> stack = new TwoStack<>(10);
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) {
stack.push1(i + "");
} else {
stack.push2(i + "");
}
}
stack.clear();
assertTrue(stack.empty());
}
}