-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStackTest.java
More file actions
82 lines (61 loc) · 1.59 KB
/
StackTest.java
File metadata and controls
82 lines (61 loc) · 1.59 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
82
package dataStructures.stack;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class StackTest {
@Test
@DisplayName("find minimal value in the stack")
public void testGetMin() {
Stack s = new Stack();
s.push(-2);
s.push(0);
s.push(-3);
int actual = s.getMin();
int expected = -3;
assertEquals(expected, actual, "getMin() should work");
System.out.println("Test - Stack : getMin() - passed ok");
}
@Test
@DisplayName("find last added value in the stack")
public void testPeek() {
Stack s = new Stack();
s.push(-1);
s.push(0);
s.push(2);
s.push(5);
s.push(4);
int actual = s.peek();
int expected = 4;
assertEquals(expected, actual, "peek() should work");
System.out.println("Test - Stack : peek() - passed ok");
}
@Test
public void testPop() {
Stack s = new Stack();
s.push(-1);
s.push(0);
s.push(2);
s.push(5);
s.push(4);
s.pop();
s.push(5);
String actual = s.stack.toString();
String expected = "null<-(-1)<-(0)<-(2)<-(5)<-(5)";
assertEquals(expected, actual, "pop() should work");
System.out.println("Test - Stack : pop(data) - passed ok");
}
@Test
@DisplayName("test addition to the stack")
public void testPush() {
Stack s = new Stack();
s.push(-1);
s.push(0);
s.push(2);
s.push(5);
s.push(4);
String actual = s.stack.toString();
String expected = "null<-(-1)<-(0)<-(2)<-(5)<-(4)";
assertEquals(expected, actual, "addition with push() should work");
System.out.println("Test - Stack : push(data) - passed ok");
}
}