Skip to content

Commit 6e4c0fd

Browse files
fix: correct import order for clang-format compliance
1 parent d98fe62 commit 6e4c0fd

1 file changed

Lines changed: 50 additions & 16 deletions

File tree

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,103 @@
11
package com.thealgorithms.datastructures.stacks;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
38
import org.junit.jupiter.api.Test;
4-
import static org.junit.jupiter.api.Assertions.*;
59

610
class StackUsingLinkedListTest {
7-
11+
812
@Test
913
void testPushAndPop() {
1014
StackUsingLinkedList stack = new StackUsingLinkedList();
1115
stack.push(10);
1216
stack.push(20);
1317
stack.push(30);
14-
18+
1519
assertEquals(30, stack.pop());
1620
assertEquals(20, stack.pop());
1721
assertEquals(10, stack.pop());
1822
}
19-
23+
2024
@Test
2125
void testPeek() {
2226
StackUsingLinkedList stack = new StackUsingLinkedList();
2327
stack.push(100);
2428
stack.push(200);
25-
29+
2630
assertEquals(200, stack.peek());
2731
assertEquals(200, stack.peek());
32+
assertEquals(2, stack.size());
2833
}
29-
34+
3035
@Test
3136
void testIsEmpty() {
3237
StackUsingLinkedList stack = new StackUsingLinkedList();
3338
assertTrue(stack.isEmpty());
34-
39+
3540
stack.push(5);
3641
assertFalse(stack.isEmpty());
37-
42+
3843
stack.pop();
3944
assertTrue(stack.isEmpty());
4045
}
41-
46+
4247
@Test
4348
void testSize() {
4449
StackUsingLinkedList stack = new StackUsingLinkedList();
4550
assertEquals(0, stack.size());
46-
51+
4752
stack.push(1);
4853
assertEquals(1, stack.size());
49-
54+
5055
stack.push(2);
5156
stack.push(3);
5257
assertEquals(3, stack.size());
53-
58+
5459
stack.pop();
5560
assertEquals(2, stack.size());
5661
}
57-
62+
5863
@Test
5964
void testPopEmptyStack() {
6065
StackUsingLinkedList stack = new StackUsingLinkedList();
61-
assertThrows(RuntimeException.class, () -> stack.pop());
66+
assertThrows(RuntimeException.class, stack::pop);
6267
}
63-
68+
6469
@Test
6570
void testPeekEmptyStack() {
6671
StackUsingLinkedList stack = new StackUsingLinkedList();
67-
assertThrows(RuntimeException.class, () -> stack.peek());
72+
assertThrows(RuntimeException.class, stack::peek);
73+
}
74+
75+
@Test
76+
void testMultipleOperations() {
77+
StackUsingLinkedList stack = new StackUsingLinkedList();
78+
79+
assertTrue(stack.isEmpty());
80+
81+
stack.push(1);
82+
stack.push(2);
83+
assertEquals(2, stack.pop());
84+
85+
stack.push(3);
86+
stack.push(4);
87+
assertEquals(4, stack.peek());
88+
assertEquals(3, stack.size());
89+
90+
assertFalse(stack.isEmpty());
91+
}
92+
93+
@Test
94+
void testSingleElement() {
95+
StackUsingLinkedList stack = new StackUsingLinkedList();
96+
stack.push(42);
97+
98+
assertEquals(42, stack.peek());
99+
assertEquals(1, stack.size());
100+
assertEquals(42, stack.pop());
101+
assertTrue(stack.isEmpty());
68102
}
69103
}

0 commit comments

Comments
 (0)