-
-
Notifications
You must be signed in to change notification settings - Fork 314
/
Copy pathSortStackTest.java
46 lines (38 loc) · 1.06 KB
/
SortStackTest.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
package com.ctci.stacksandqueues;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Stack;
import org.junit.jupiter.api.Test;
class SortStackTest {
@Test
void testCase1() {
Stack<Integer> unsortedStack = new Stack<>();
unsortedStack.push(2);
unsortedStack.push(5);
unsortedStack.push(1);
unsortedStack.push(3);
SortStack.sortStack(unsortedStack);
assertEquals(1,unsortedStack.pop());
assertEquals(2,unsortedStack.pop());
assertEquals(3,unsortedStack.pop());
assertEquals(5,unsortedStack.pop());
}
@Test
void testCase2() {
Stack<Integer> unsortedStack = new Stack<>();
SortStack.sortStack(unsortedStack);
assertTrue(unsortedStack.isEmpty());
}
@Test
void testCase3() {
Stack<Integer> unsortedStack = new Stack<>();
unsortedStack.push(5);
unsortedStack.push(3);
unsortedStack.push(2);
unsortedStack.push(1);
SortStack.sortStack(unsortedStack);
assertEquals(1,unsortedStack.pop());
assertEquals(2,unsortedStack.pop());
assertEquals(3,unsortedStack.pop());
assertEquals(5,unsortedStack.pop());
}
}