From 6e48ce81375ac9b0aae743646c36048425d0e775 Mon Sep 17 00:00:00 2001 From: alxkm Date: Mon, 14 Jul 2025 23:20:33 +0200 Subject: [PATCH 1/3] testing: improve test coverage SortedLinkedListTest --- .../lists/SortedLinkedListTest.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java index 82e0853da374..44e6fdcf0382 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java @@ -128,4 +128,82 @@ public void testIsEmptyAfterDeletion() { list.delete(10); assertTrue(list.isEmpty()); } + + @Test + public void testInsertNegativeNumbers() { + list.insert(-10); + list.insert(-5); + list.insert(-20); + assertEquals("[-20, -10, -5]", list.toString()); + } + + @Test + public void testInsertMixedPositiveAndNegativeNumbers() { + list.insert(0); + list.insert(-1); + list.insert(1); + assertEquals("[-1, 0, 1]", list.toString()); + } + + @Test + public void testMultipleDeletesUntilEmpty() { + list.insert(2); + list.insert(4); + list.insert(6); + assertTrue(list.delete(4)); + assertTrue(list.delete(2)); + assertTrue(list.delete(6)); + assertTrue(list.isEmpty()); + assertEquals("[]", list.toString()); + } + + @Test + public void testDeleteDuplicateValuesOnlyDeletesOneInstance() { + list.insert(5); + list.insert(5); + list.insert(5); + assertTrue(list.delete(5)); + assertEquals("[5, 5]", list.toString()); + assertTrue(list.delete(5)); + assertEquals("[5]", list.toString()); + assertTrue(list.delete(5)); + assertEquals("[]", list.toString()); + } + + @Test + public void testSearchOnListWithDuplicates() { + list.insert(7); + list.insert(7); + list.insert(7); + assertTrue(list.search(7)); + assertFalse(list.search(10)); + } + + @Test + public void testToStringOnEmptyList() { + assertEquals("[]", list.toString()); + } + + + @Test + public void testDeleteAllDuplicates() { + list.insert(4); + list.insert(4); + list.insert(4); + assertTrue(list.delete(4)); + assertTrue(list.delete(4)); + assertTrue(list.delete(4)); + assertFalse(list.delete(4)); // nothing left to delete + assertEquals("[]", list.toString()); + } + + @Test + public void testInsertAfterDeletion() { + list.insert(1); + list.insert(3); + list.insert(5); + assertTrue(list.delete(3)); + list.insert(2); + assertEquals("[1, 2, 5]", list.toString()); + } } From 8ee8d244ca039a98a6a2609b5ad6f676791b89e6 Mon Sep 17 00:00:00 2001 From: alxkm Date: Mon, 14 Jul 2025 23:23:33 +0200 Subject: [PATCH 2/3] checkstyle: fix comments formatting --- .../datastructures/lists/SortedLinkedListTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java index 44e6fdcf0382..b8d174aba32a 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java @@ -193,7 +193,7 @@ public void testDeleteAllDuplicates() { assertTrue(list.delete(4)); assertTrue(list.delete(4)); assertTrue(list.delete(4)); - assertFalse(list.delete(4)); // nothing left to delete + assertFalse(list.delete(4)); // nothing left to delete assertEquals("[]", list.toString()); } From 262f8e8b3b497df7c07b7e50e4d3e82d83076ee6 Mon Sep 17 00:00:00 2001 From: alxkm Date: Mon, 14 Jul 2025 23:24:41 +0200 Subject: [PATCH 3/3] checkstyle: fix formatting --- .../thealgorithms/datastructures/lists/SortedLinkedListTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java index b8d174aba32a..71f932465eef 100644 --- a/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java +++ b/src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java @@ -184,7 +184,6 @@ public void testToStringOnEmptyList() { assertEquals("[]", list.toString()); } - @Test public void testDeleteAllDuplicates() { list.insert(4); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy