Skip to content

Commit 2045e60

Browse files
committed
fix: add generic type parameters to resolve compilation warnings
1 parent f49bff7 commit 2045e60

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

src/test/java/com/thealgorithms/datastructures/stacks/StackUsingLinkedListTest.java

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,96 +8,83 @@
88
import org.junit.jupiter.api.Test;
99

1010
class StackUsingLinkedListTest {
11-
1211
@Test
1312
void testPushAndPop() {
14-
StackUsingLinkedList stack = new StackUsingLinkedList();
13+
StackUsingLinkedList<Integer> stack = new StackUsingLinkedList<>();
1514
stack.push(10);
1615
stack.push(20);
1716
stack.push(30);
18-
1917
assertEquals(30, stack.pop());
2018
assertEquals(20, stack.pop());
2119
assertEquals(10, stack.pop());
2220
}
2321

2422
@Test
2523
void testPeek() {
26-
StackUsingLinkedList stack = new StackUsingLinkedList();
24+
StackUsingLinkedList<Integer> stack = new StackUsingLinkedList<>();
2725
stack.push(100);
2826
stack.push(200);
29-
3027
assertEquals(200, stack.peek());
3128
assertEquals(200, stack.peek());
3229
assertEquals(2, stack.size());
3330
}
3431

3532
@Test
3633
void testIsEmpty() {
37-
StackUsingLinkedList stack = new StackUsingLinkedList();
34+
StackUsingLinkedList<Integer> stack = new StackUsingLinkedList<>();
3835
assertTrue(stack.isEmpty());
39-
4036
stack.push(5);
4137
assertFalse(stack.isEmpty());
42-
4338
stack.pop();
4439
assertTrue(stack.isEmpty());
4540
}
4641

4742
@Test
4843
void testSize() {
49-
StackUsingLinkedList stack = new StackUsingLinkedList();
44+
StackUsingLinkedList<Integer> stack = new StackUsingLinkedList<>();
5045
assertEquals(0, stack.size());
51-
5246
stack.push(1);
5347
assertEquals(1, stack.size());
54-
5548
stack.push(2);
5649
stack.push(3);
5750
assertEquals(3, stack.size());
58-
5951
stack.pop();
6052
assertEquals(2, stack.size());
6153
}
6254

6355
@Test
6456
void testPopEmptyStack() {
65-
StackUsingLinkedList stack = new StackUsingLinkedList();
57+
StackUsingLinkedList<Integer> stack = new StackUsingLinkedList<>();
6658
assertThrows(RuntimeException.class, stack::pop);
6759
}
6860

6961
@Test
7062
void testPeekEmptyStack() {
71-
StackUsingLinkedList stack = new StackUsingLinkedList();
63+
StackUsingLinkedList<Integer> stack = new StackUsingLinkedList<>();
7264
assertThrows(RuntimeException.class, stack::peek);
7365
}
7466

7567
@Test
7668
void testMultipleOperations() {
77-
StackUsingLinkedList stack = new StackUsingLinkedList();
78-
69+
StackUsingLinkedList<Integer> stack = new StackUsingLinkedList<>();
7970
assertTrue(stack.isEmpty());
80-
8171
stack.push(1);
8272
stack.push(2);
8373
assertEquals(2, stack.pop());
84-
8574
stack.push(3);
8675
stack.push(4);
8776
assertEquals(4, stack.peek());
8877
assertEquals(3, stack.size());
89-
9078
assertFalse(stack.isEmpty());
9179
}
9280

9381
@Test
9482
void testSingleElement() {
95-
StackUsingLinkedList stack = new StackUsingLinkedList();
83+
StackUsingLinkedList<Integer> stack = new StackUsingLinkedList<>();
9684
stack.push(42);
97-
9885
assertEquals(42, stack.peek());
9986
assertEquals(1, stack.size());
10087
assertEquals(42, stack.pop());
10188
assertTrue(stack.isEmpty());
10289
}
103-
}
90+
}

0 commit comments

Comments
 (0)