mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 06:23:08 +08:00
* Added code to find Articulation Points and Bridges * tried to solve clang-formant test * removed new line at EOF to get lint to pass * feature: Added Ahocorasick Algorithm * fixed lint using clang-format * Added QuickSort Algorithm for linked list * removed datastructures/graphs/ArticulationPointsAndBridges and string/AhoCorasick.java from this branch * Added datastructures/lists/SinglyLinkedList class, Replaced ListNode class * Modified some comments * Added tests in QuickSortLinkedListsTest.java * removed main as added a test file to test test-cases * test file for QuickSortLinkedLinst.java
This commit is contained in:
@ -0,0 +1,66 @@
|
||||
package com.thealgorithms.datastructures.lists;
|
||||
|
||||
/**
|
||||
* Test cases for QuickSortLinkedList
|
||||
* Author: Prabhat-Kumar-42
|
||||
* GitHub: https://github.com/Prabhat-Kumar-42
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class QuickSortLinkedListTest {
|
||||
|
||||
@Test
|
||||
public void testSortEmptyList() {
|
||||
SinglyLinkedList emptyList = new SinglyLinkedList();
|
||||
QuickSortLinkedList sorter = new QuickSortLinkedList(emptyList);
|
||||
|
||||
// Test case: Sorting an empty list should result in an empty list
|
||||
sorter.sortList();
|
||||
assertNull(emptyList.getHead());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortSingleNodeList() {
|
||||
SinglyLinkedList singleNodeList = new SinglyLinkedList();
|
||||
singleNodeList.insert(5);
|
||||
QuickSortLinkedList sorter = new QuickSortLinkedList(singleNodeList);
|
||||
|
||||
// Test case: Sorting a list with a single node should result in the same list
|
||||
sorter.sortList();
|
||||
assertEquals(5, singleNodeList.getHead().value);
|
||||
assertNull(singleNodeList.getHead().next);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortMultipleElementsList() {
|
||||
SinglyLinkedList list = new SinglyLinkedList();
|
||||
list.insert(5);
|
||||
list.insert(3);
|
||||
list.insert(8);
|
||||
list.insert(1);
|
||||
list.insert(10);
|
||||
list.insert(2);
|
||||
list.insert(7);
|
||||
list.insert(4);
|
||||
list.insert(9);
|
||||
list.insert(6);
|
||||
QuickSortLinkedList sorter = new QuickSortLinkedList(list);
|
||||
|
||||
// Test case: Sorting a list with multiple elements
|
||||
sorter.sortList();
|
||||
assertEquals(1, list.getHead().value);
|
||||
assertEquals(2, list.getHead().next.value);
|
||||
assertEquals(3, list.getHead().next.next.value);
|
||||
assertEquals(4, list.getHead().next.next.next.value);
|
||||
assertEquals(5, list.getHead().next.next.next.next.value);
|
||||
assertEquals(6, list.getHead().next.next.next.next.next.value);
|
||||
assertEquals(7, list.getHead().next.next.next.next.next.next.value);
|
||||
assertEquals(8, list.getHead().next.next.next.next.next.next.next.value);
|
||||
assertEquals(9, list.getHead().next.next.next.next.next.next.next.next.value);
|
||||
assertEquals(10, list.getHead().next.next.next.next.next.next.next.next.next.value);
|
||||
assertNull(list.getHead().next.next.next.next.next.next.next.next.next.next);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user