diff --git a/src/main/java/com/thealgorithms/sorts/MergeSortRecursive.java b/src/main/java/com/thealgorithms/sorts/MergeSortRecursive.java index 9d77827c..57f1d9be 100644 --- a/src/main/java/com/thealgorithms/sorts/MergeSortRecursive.java +++ b/src/main/java/com/thealgorithms/sorts/MergeSortRecursive.java @@ -12,9 +12,9 @@ public class MergeSortRecursive { this.arr = arr; } - public void mergeSort() { + public List mergeSort() { List arrSorted = merge(arr); - System.out.println(arrSorted); + return arrSorted; } private static List merge(List arr) { diff --git a/src/test/java/com/thealgorithms/sorts/HeapSortTest.java b/src/test/java/com/thealgorithms/sorts/HeapSortTest.java new file mode 100644 index 00000000..7b34c59f --- /dev/null +++ b/src/test/java/com/thealgorithms/sorts/HeapSortTest.java @@ -0,0 +1,35 @@ +package com.thealgorithms.sorts; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + +import org.junit.jupiter.api.Test; + +public class HeapSortTest { + + private HeapSort heapSort = new HeapSort(); + + @Test + void testHeapSortCase1() { + Integer[] array = { 49, 4, 36, 9, 144, 1 }; + Integer[] sorted = heapSort.sort(array); + Integer[] expected = { 1, 4, 9, 36, 49, 144 }; + assertArrayEquals(expected, sorted); + } + + @Test + void testHeapSortCase2() { + Integer[] array = { }; + Integer[] sorted = heapSort.sort(array); + Integer[] expected = { }; + assertArrayEquals(expected, sorted); + } + + @Test + void testHeapSortCase3 () { + Integer[] array = { -3, 5, 3, 4, 3, 7, 40, -20, 30, 0 }; + Integer[] sorted = heapSort.sort(array); + Integer[] expected = { -20, -3, 0, 3, 3, 4, 5, 7, 30, 40 }; + assertArrayEquals(expected, sorted); + } + +} diff --git a/src/test/java/com/thealgorithms/sorts/MergeSortRecursiveTest.java b/src/test/java/com/thealgorithms/sorts/MergeSortRecursiveTest.java new file mode 100644 index 00000000..8bc7c0b2 --- /dev/null +++ b/src/test/java/com/thealgorithms/sorts/MergeSortRecursiveTest.java @@ -0,0 +1,35 @@ +package com.thealgorithms.sorts; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.Test; + +public class MergeSortRecursiveTest { + +// private MergeSortRecursive mergeSortRecursive = new MergeSortRecursive(); + + @Test + void testMergeSortRecursiveCase1 () { + MergeSortRecursive mergeSortRecursive = new MergeSortRecursive(Arrays.asList(5, 12, 9, 3, 15, 88)); + + List expected = Arrays.asList(3, 5, 9, 12, 15, 88); + List sorted = mergeSortRecursive.mergeSort(); + + assertEquals(expected, sorted); + } + + @Test + void testMergeSortRecursiveCase2 () { + MergeSortRecursive mergeSortRecursive = new MergeSortRecursive(Arrays.asList(-3, 5, 3, 4, 3, 7, 40, -20, 30, 0)); + + List expected = Arrays.asList(-20, -3, 0, 3, 3, 4, 5, 7, 30, 40); + List sorted = mergeSortRecursive.mergeSort(); + + assertEquals(expected, sorted); + } + +}