File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
src/test/java/com/thealgorithms/stacks Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .thealgorithms .stacks ;
2+
3+ import org .junit .jupiter .api .BeforeEach ;
4+ import org .junit .jupiter .api .Test ;
5+
6+ import static org .junit .jupiter .api .Assertions .*;
7+
8+ public class StackUsingLinkedListTest {
9+ private StackUsingLinkedList <Integer > stack ;
10+
11+ @ BeforeEach
12+ public void setUp () {
13+ stack = new StackUsingLinkedList <>();
14+ }
15+
16+ @ Test
17+ public void testPushAndPeek () {
18+ stack .push (10 );
19+ stack .push (20 );
20+
21+ assertEquals (20 , stack .peek ());
22+ }
23+
24+ @ Test
25+ public void testPop () {
26+ stack .push (5 );
27+ stack .push (15 );
28+ int popped = stack .pop ();
29+ assertEquals (15 , popped );
30+ assertEquals (5 , stack .peek ());
31+ }
32+
33+ @ Test
34+ public void testIsEmpty () {
35+ assertTrue (stack .isEmpty ());
36+ stack .push (1 );
37+ assertFalse (stack .isEmpty ());
38+ }
39+
40+ @ Test
41+ public void testSize () {
42+ assertEquals (0 , stack .size ());
43+ stack .push (1 );
44+ stack .push (2 );
45+ assertEquals (2 , stack .size ());
46+ }
47+
48+ @ Test
49+ public void testPopOnEmptyStack () {
50+ assertThrows (RuntimeException .class , () -> stack .pop ());
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments