Repository: TheAlgorithms/Java
Pull request #3510 (2022-10-12 02:56:26)

Merge sort recursive test
### **Describe your change:**

- [ ] Add an algorithm?
- [x] Fix a bug or typo in an existing algorithm?
- [ ] Documentation change?

#### References

<!-- Add any reference to previous pull-request or issue -->

### **Checklist:**

<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized.
- [x] I know that pull requests will not be merged if they fail the automated tests.
- [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
- [x] All new Java files are placed inside an existing directory.
- [x] All filenames are in all uppercase characters with no spaces or dashes.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
- [x] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.


github-actions[bot]: This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Patch:
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<Integer> mergeSort() {
         List<Integer> arrSorted = merge(arr);
-        System.out.println(arrSorted);
+        return arrSorted;
     }
 
     private static List<Integer> merge(List<Integer> arr) {


Test patch:
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<Integer> expected = Arrays.asList(3, 5, 9, 12, 15, 88);
+		List<Integer> 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<Integer> expected = Arrays.asList(-20, -3, 0, 3, 3, 4, 5, 7, 30, 40);
+		List<Integer> sorted = mergeSortRecursive.mergeSort();
+		
+		assertEquals(expected, sorted);
+	}
+
+}