Skip to content

Commit d0d4b3c

Browse files
testing: additional testcases for CountSinglyLinkedListRecursionTest (#6392)
testing: additional testcases for CountSinglyLinkedListRecursionTest Co-authored-by: Deniz Altunkapan <[email protected]>
1 parent 2f2a32b commit d0d4b3c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/test/java/com/thealgorithms/datastructures/lists/CountSinglyLinkedListRecursionTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,39 @@ public void testCountWithDuplicateElements() {
4646
list.insert(3);
4747
assertEquals(5, list.count(), "Count of a list with duplicate elements should match total node count.");
4848
}
49+
50+
@Test
51+
public void testCountAfterClearingList() {
52+
for (int i = 1; i <= 4; i++) {
53+
list.insert(i);
54+
}
55+
list.clear(); // assuming you have a clear method; if not, skip this
56+
assertEquals(0, list.count(), "Count after clearing the list should be 0.");
57+
}
58+
59+
@Test
60+
public void testCountOnVeryLargeList() {
61+
int n = 1000;
62+
for (int i = 0; i < n; i++) {
63+
list.insert(i);
64+
}
65+
assertEquals(n, list.count(), "Count should correctly return for large list sizes.");
66+
}
67+
68+
@Test
69+
public void testCountOnListWithNegativeNumbers() {
70+
list.insert(-1);
71+
list.insert(-5);
72+
list.insert(-10);
73+
assertEquals(3, list.count(), "Count should correctly handle negative values.");
74+
}
75+
76+
@Test
77+
public void testCountIsConsistentWithoutModification() {
78+
list.insert(1);
79+
list.insert(2);
80+
int firstCount = list.count();
81+
int secondCount = list.count();
82+
assertEquals(firstCount, secondCount, "Repeated count calls should return consistent values.");
83+
}
4984
}

0 commit comments

Comments
 (0)