add sort test

This commit is contained in:
Daniel Langbein 2024-12-16 21:30:53 +00:00
parent ccd0fba7c2
commit d19d89006c
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002

View File

@ -1,10 +1,13 @@
package de.uni_marburg.powersort.sort; package de.uni_marburg.powersort.sort;
import de.uni_marburg.powersort.JUnitUtil; import de.uni_marburg.powersort.JUnitUtil;
import de.uni_marburg.powersort.data.AscendingRuns;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.converter.ConvertWith;
import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.CsvSource;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
public abstract class AbstractSortTest { public abstract class AbstractSortTest {
@ -12,14 +15,31 @@ public abstract class AbstractSortTest {
@ParameterizedTest @ParameterizedTest
@CsvSource({ @CsvSource({
"'',''", "''",
"'1337','1337'", "1337",
"'3|2|1','1|2|3'", "3|2|1",
"'1|1','1|1'", "1|1",
"'2|1','1|2'", "2|1",
"'2|1|2','1|2|2'", "2|1|2",
}) })
void test1(@ConvertWith(JUnitUtil.IntegerArrayConverter.class) Integer[] array, @ConvertWith(JUnitUtil.IntegerArrayConverter.class) Integer[] expected) { void test1(@ConvertWith(JUnitUtil.IntegerArrayConverter.class) Integer[] array) {
sortAndCheckResult(array);
}
@ParameterizedTest
@CsvSource({
"3,7,-13",
"3,7,-3",
})
void test2(int numOfRuns, int runLength, int decreaseBetweenRuns) {
Integer[] array = AscendingRuns.newAscendingRuns(numOfRuns, runLength, decreaseBetweenRuns).getCopy();
sortAndCheckResult(array);
}
void sortAndCheckResult(Integer[] array){
Integer[] expected = Arrays.copyOf(array, array.length);
Arrays.sort(expected);
sortAlg.get().sort(array); sortAlg.get().sort(array);
assertArrayEquals(expected, array); assertArrayEquals(expected, array);
} }