Skip to content

Commit 0348174

Browse files
committed
feat: stack unit test
1 parent 7b1e6fb commit 0348174

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package test.dataStructures.stack;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import src.dataStructures.stack.Stack;
6+
public class StackTest {
7+
@Test
8+
public void testEmpty(){
9+
Stack<Integer> stk = new Stack<>();
10+
Assert.assertEquals(stk.pop(), null);
11+
Assert.assertEquals(stk.peek(), null);
12+
}
13+
14+
@Test
15+
public void testPopAndPeek() {
16+
Stack<Integer> stk = new Stack<>(1, 2, 3);
17+
Assert.assertEquals(stk.peek().toString(), "3");
18+
Assert.assertEquals(stk.pop().toString(), "3");
19+
Assert.assertEquals(stk.peek().toString(), "2");
20+
}
21+
22+
@Test
23+
public void testPush() {
24+
Stack<Integer> stk = new Stack<>();
25+
stk.push(1);
26+
Assert.assertEquals(stk.peek().toString(), "1");
27+
stk.push(2);
28+
stk.push(3);
29+
Assert.assertEquals(stk.peek().toString(), "3");
30+
}
31+
32+
}

0 commit comments

Comments
 (0)