[JAVA-18123] Upgraded algorithms-modules to java 11 + Upgraded unit t… (#13437)

* [JAVA-18123] Upgraded algorithms-modules to java 11 + Upgraded unit tests to junit5

* [JAVA-18123] Clean up properties

---------

Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com>
This commit is contained in:
panos-kakos
2023-02-07 14:42:21 +00:00
committed by GitHub
parent 2c0c3b269e
commit d47969ce2d
82 changed files with 740 additions and 721 deletions

View File

@@ -4,10 +4,10 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.jupiter.api.Test;
public class BubbleSortUnitTest {
class BubbleSortUnitTest {
@Test
public void givenIntegerArray_whenSortedWithBubbleSort_thenGetSortedArray() {
void givenIntegerArray_whenSortedWithBubbleSort_thenGetSortedArray() {
Integer[] array = { 2, 1, 4, 6, 3, 5 };
Integer[] sortedArray = { 1, 2, 3, 4, 5, 6 };
BubbleSort bubbleSort = new BubbleSort();
@@ -16,7 +16,7 @@ public class BubbleSortUnitTest {
}
@Test
public void givenIntegerArray_whenSortedWithOptimizedBubbleSort_thenGetSortedArray() {
void givenIntegerArray_whenSortedWithOptimizedBubbleSort_thenGetSortedArray() {
Integer[] array = { 2, 1, 4, 6, 3, 5 };
Integer[] sortedArray = { 1, 2, 3, 4, 5, 6 };
BubbleSort bubbleSort = new BubbleSort();

View File

@@ -1,24 +1,26 @@
package com.baeldung.algorithms.bucketsort;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class IntegerBucketSorterUnitTest {
class IntegerBucketSorterUnitTest {
private IntegerBucketSorter sorter;
@Before
@BeforeEach
public void setUp() throws Exception {
sorter = new IntegerBucketSorter();
}
@Test
public void givenUnsortedList_whenSortedUsingBucketSorter_checkSortingCorrect() {
void givenUnsortedList_whenSortedUsingBucketSorter_checkSortingCorrect() {
List<Integer> unsorted = Arrays.asList(80,50,60,30,20,10,70,0,40,500,600,602,200,15);
List<Integer> expected = Arrays.asList(0,10,15,20,30,40,50,60,70,80,200,500,600,602);
@@ -26,7 +28,5 @@ public class IntegerBucketSorterUnitTest {
List<Integer> actual = sorter.sort(unsorted);
assertEquals(expected, actual);
}
}

View File

@@ -1,16 +1,16 @@
package com.baeldung.algorithms.heapsort;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class HeapUnitTest {
class HeapUnitTest {
@Test
public void givenNotEmptyHeap_whenPopCalled_thenItShouldReturnSmallestElement() {
void givenNotEmptyHeap_whenPopCalled_thenItShouldReturnSmallestElement() {
// given
Heap<Integer> heap = Heap.of(3, 5, 1, 4, 2);
@@ -22,7 +22,7 @@ public class HeapUnitTest {
}
@Test
public void givenNotEmptyIterable_whenSortCalled_thenItShouldReturnElementsInSortedList() {
void givenNotEmptyIterable_whenSortCalled_thenItShouldReturnElementsInSortedList() {
// given
List<Integer> elements = Arrays.asList(3, 5, 1, 4, 2);

View File

@@ -1,25 +1,25 @@
package com.baeldung.algorithms.insertionsort;
import com.baeldung.algorithms.insertionsort.InsertionSort;
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
public class InsertionSortUnitTest {
import org.junit.jupiter.api.Test;
class InsertionSortUnitTest {
@Test
public void givenUnsortedArray_whenInsertionSortImperative_thenSortedAsc() {
void givenUnsortedArray_whenInsertionSortImperative_thenSortedAsc() {
int[] input = {6, 2, 3, 4, 5, 1};
InsertionSort.insertionSortImperative(input);
int[] expected = {1, 2, 3, 4, 5, 6};
assertArrayEquals("the two arrays are not equal", expected, input);
assertArrayEquals(expected, input, "the two arrays are not equal");
}
@Test
public void givenUnsortedArray_whenInsertionSortRecursive_thenSortedAsc() {
void givenUnsortedArray_whenInsertionSortRecursive_thenSortedAsc() {
int[] input = {6, 4, 5, 2, 3, 1};
InsertionSort.insertionSortRecursive(input);
int[] expected = {1, 2, 3, 4, 5, 6};
assertArrayEquals("the two arrays are not equal", expected, input);
assertArrayEquals( expected, input, "the two arrays are not equal");
}
}

View File

@@ -1,17 +1,17 @@
package com.baeldung.algorithms.mergesort;
import org.junit.Assert;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class MergeSortUnitTest {
class MergeSortUnitTest {
@Test
public void positiveTest() {
void positiveTest() {
int[] actual = { 5, 1, 6, 2, 3, 4 };
int[] expected = { 1, 2, 3, 4, 5, 6 };
MergeSort.mergeSort(actual, actual.length);
Assert.assertArrayEquals(expected, actual);
assertArrayEquals(expected, actual);
}
}

View File

@@ -1,17 +1,17 @@
package com.baeldung.algorithms.quicksort;
import com.baeldung.algorithms.quicksort.QuickSort;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
public class QuickSortUnitTest {
import org.junit.jupiter.api.Test;
class QuickSortUnitTest {
@Test
public void givenIntegerArray_whenSortedWithQuickSort_thenGetSortedArray() {
void givenIntegerArray_whenSortedWithQuickSort_thenGetSortedArray() {
int[] actual = { 9, 5, 1, 0, 6, 2, 3, 4, 7, 8 };
int[] expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
QuickSort.quickSort(actual, 0, actual.length-1);
Assert.assertArrayEquals(expected, actual);
assertArrayEquals(expected, actual);
}
}

View File

@@ -1,15 +1,16 @@
package com.baeldung.algorithms.quicksort;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
public class ThreeWayQuickSortUnitTest {
import org.junit.jupiter.api.Test;
class ThreeWayQuickSortUnitTest {
@Test
public void givenIntegerArray_whenSortedWithThreeWayQuickSort_thenGetSortedArray() {
int[] actual = { 3, 5, 5, 5, 3, 7, 7, 3, 5, 5, 7, 3, 3 };
int[] expected = { 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 7, 7, 7 };
ThreeWayQuickSort.threeWayQuickSort(actual, 0, actual.length-1);
Assert.assertArrayEquals(expected, actual);
assertArrayEquals(expected, actual);
}
}

View File

@@ -1,13 +1,13 @@
package com.baeldung.algorithms.radixsort;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class RadixSortUnitTest {
class RadixSortUnitTest {
@Test
public void givenUnsortedArray_whenRadixSort_thenArraySorted() {
void givenUnsortedArray_whenRadixSort_thenArraySorted() {
int[] numbers = { 387, 468, 134, 123, 68, 221, 769, 37, 7 };
RadixSort.sort(numbers);
int[] numbersSorted = { 7, 37, 68, 123, 134, 221, 387, 468, 769 };

View File

@@ -1,25 +1,24 @@
package com.baeldung.algorithms.selectionsort;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class SelectionSortUnitTest {
class SelectionSortUnitTest {
@Test
public void givenUnsortedArray_whenSelectionSort_SortAscending_thenSortedAsc() {
void givenUnsortedArray_whenSelectionSort_SortAscending_thenSortedAsc() {
int[] input = { 5, 4, 1, 6, 2 };
SelectionSort.sortAscending(input);
int[] expected = {1, 2, 4, 5, 6};
assertArrayEquals("the two arrays are not equal", expected, input);
assertArrayEquals(expected, input, "the two arrays are not equal");
}
@Test
public void givenUnsortedArray_whenSelectionSort_SortDescending_thenSortedDesc() {
void givenUnsortedArray_whenSelectionSort_SortDescending_thenSortedDesc() {
int[] input = { 5, 4, 1, 6, 2 };
SelectionSort.sortDescending(input);
int[] expected = {6, 5, 4, 2, 1};
assertArrayEquals("the two arrays are not equal", expected, input);
assertArrayEquals(expected, input, "the two arrays are not equal");
}
}

View File

@@ -1,17 +1,17 @@
package com.baeldung.algorithms.shellsort;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
public class ShellSortUnitTest {
import org.junit.jupiter.api.Test;
class ShellSortUnitTest {
@Test
public void givenUnsortedArray_whenShellSort_thenSortedAsc() {
void givenUnsortedArray_whenShellSort_thenSortedAsc() {
int[] input = {41, 15, 82, 5, 65, 19, 32, 43, 8};
ShellSort.sort(input);
int[] expected = {5, 8, 15, 19, 32, 41, 43, 65, 82};
assertArrayEquals("the two arrays are not equal", expected, input);
assertArrayEquals( expected, input, "the two arrays are not equal");
}
}