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:
Alex K
2024-06-20 18:47:43 +03:00
committed by GitHub
parent 91101ec424
commit 15d2e70673
2 changed files with 62 additions and 55 deletions

View File

@ -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();
}
}