mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-28 06:55:02 +08:00
Refactoring and code improving for StrandSort (#5243)
* Refactoring and code improving for StrandSort * Fix java checkstyle * Fix "Each variable declaration must be in its own statement" * Fix "uses integer based for loops to iterate over a List" --------- Co-authored-by: alx <alx@alx.com>
This commit is contained in:
@ -1,34 +1,8 @@
|
||||
package com.thealgorithms.sorts;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class StrandSortTest {
|
||||
|
||||
@Test
|
||||
// valid test case
|
||||
public void strandSortNonDuplicateTest() {
|
||||
int[] expectedArray = {1, 2, 3, 4, 5};
|
||||
LinkedList<Integer> actualList = StrandSort.strandSort(new LinkedList<Integer>(Arrays.asList(3, 1, 2, 4, 5)));
|
||||
int[] actualArray = new int[actualList.size()];
|
||||
for (int i = 0; i < actualList.size(); i++) {
|
||||
actualArray[i] = actualList.get(i);
|
||||
}
|
||||
assertArrayEquals(expectedArray, actualArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
// valid test case
|
||||
public void strandSortDuplicateTest() {
|
||||
int[] expectedArray = {2, 2, 2, 5, 7};
|
||||
LinkedList<Integer> actualList = StrandSort.strandSort(new LinkedList<Integer>(Arrays.asList(7, 2, 2, 2, 5)));
|
||||
int[] actualArray = new int[actualList.size()];
|
||||
for (int i = 0; i < actualList.size(); i++) {
|
||||
actualArray[i] = actualList.get(i);
|
||||
}
|
||||
assertArrayEquals(expectedArray, actualArray);
|
||||
class StrandSortTest extends SortingAlgorithmTest {
|
||||
@Override
|
||||
SortAlgorithm getSortAlgorithm() {
|
||||
return new StrandSort();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user