Add tests for recursive merge sort (#3510)
This commit is contained in:
parent
b294ddcb38
commit
f7dee0d958
@ -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) {
|
||||
|
35
src/test/java/com/thealgorithms/sorts/HeapSortTest.java
Normal file
35
src/test/java/com/thealgorithms/sorts/HeapSortTest.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user