mirror of
https://gitlab.uni-marburg.de/langbeid/powersort.git
synced 2025-01-21 19:50:35 +01:00
Converted IMPL_M_1 to Generic
This commit is contained in:
parent
ebff5b6dc5
commit
a7f3ebfe50
@ -0,0 +1,89 @@
|
||||
package de.uni_marburg.powersort.MSort;
|
||||
|
||||
import static de.uni_marburg.powersort.MSort.IMPL_M_1.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PowerSortT {
|
||||
|
||||
public static void main(String[] args) {
|
||||
testFillWithAscRunsHighToLow();
|
||||
testMerge();
|
||||
testMergeInplace();
|
||||
testExtendRun();
|
||||
testPower();
|
||||
testPowerFast();
|
||||
testMergeTopmost2();
|
||||
testPowerSort();
|
||||
}
|
||||
|
||||
// Test for fillWithAscRunsHighToLow
|
||||
public static void testFillWithAscRunsHighToLow() {
|
||||
List<Integer> A = new ArrayList<>(Collections.nCopies(10, 0));
|
||||
int[] runLengths = {2, 3, 5};
|
||||
int runLenFactor = 1;
|
||||
fillWithAscRunsHighToLow(A, runLengths, runLenFactor);
|
||||
System.out.println("Test fillWithAscRunsHighToLow: " + A);
|
||||
}
|
||||
|
||||
// Test for merge
|
||||
public static void testMerge() {
|
||||
List<Integer> run1 = new ArrayList<>(Arrays.asList(1, 4, 6));
|
||||
List<Integer> run2 = new ArrayList<>(Arrays.asList(2, 3, 5));
|
||||
List<Integer> result = merge(run1, run2);
|
||||
System.out.println("Test merge: " + result);
|
||||
}
|
||||
|
||||
// Test for mergeInplace
|
||||
public static void testMergeInplace() {
|
||||
List<Integer> A = new ArrayList<>(Arrays.asList(1, 4, 6, 2, 3, 5));
|
||||
mergeInplace(A, 0, 3, 6);
|
||||
System.out.println("Test mergeInplace: " + A);
|
||||
}
|
||||
|
||||
// Test for extendRun
|
||||
public static void testExtendRun() {
|
||||
List<Integer> A = new ArrayList<>(Arrays.asList(1, 2, 3, 6, 5, 4));
|
||||
int endIndex = extendRun(A, 0);
|
||||
System.out.println("Test extendRun (from 0): " + endIndex);
|
||||
System.out.println("Modified List: " + A);
|
||||
}
|
||||
|
||||
// Test for power
|
||||
public static void testPower() {
|
||||
int[] run1 = {0, 3};
|
||||
int[] run2 = {3, 3};
|
||||
int n = 6;
|
||||
int powerValue = power(run1, run2, n);
|
||||
System.out.println("Test power: " + powerValue);
|
||||
}
|
||||
|
||||
// Test for powerFast
|
||||
public static void testPowerFast() {
|
||||
int[] run1 = {0, 3};
|
||||
int[] run2 = {3, 3};
|
||||
int n = 6;
|
||||
int powerFastValue = powerFast(run1, run2, n);
|
||||
System.out.println("Test powerFast: " + powerFastValue);
|
||||
}
|
||||
|
||||
// Test for mergeTopmost2
|
||||
public static void testMergeTopmost2() {
|
||||
List<Integer> A = new ArrayList<>(Arrays.asList(1, 3, 5, 2, 4, 6));
|
||||
List<int[]> runs = new ArrayList<>();
|
||||
runs.add(new int[]{0, 3, 1});
|
||||
runs.add(new int[]{3, 3, 1});
|
||||
mergeTopmost2(A, runs);
|
||||
System.out.println("Test mergeTopmost2: " + A);
|
||||
}
|
||||
|
||||
// Test for powerSort
|
||||
public static void testPowerSort() {
|
||||
List<Integer> A = new ArrayList<>(Arrays.asList(10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
|
||||
powerSort(A);
|
||||
System.out.println("Test powerSort: " + A);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package de.uni_marburg.powersort.MSort;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.uni_marburg.powersort.MSort.IMPL_M_1.MERGE_COST;
|
||||
import static de.uni_marburg.powersort.MSort.IMPL_M_1.fillWithAscRunsHighToLow;
|
||||
import static de.uni_marburg.powersort.MSort.IMPL_M_1.powerSort;
|
||||
|
||||
class PowerSortTest {
|
||||
@Test
|
||||
public void testWithOneInputList() {
|
||||
// List<Integer> list = new ArrayList<>(List.of(5, 2, 8, 12, 1, 6));
|
||||
// extendRun(list, 0);
|
||||
//System.out.println(list);
|
||||
// example from slides he wrote this
|
||||
int[] runs = {5, 3, 3, 14, 1, 2};
|
||||
runs = new int[]{9, 16, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
|
||||
|
||||
List<Integer> a = new ArrayList<>(IntStream.range(0, Arrays.stream(runs).sum()).boxed().collect(Collectors.toList()));
|
||||
|
||||
System.out.println();
|
||||
fillWithAscRunsHighToLow(a, runs, 1);
|
||||
MERGE_COST = 0;
|
||||
System.out.println("Sorting with Powersort:");
|
||||
powerSort(a);
|
||||
System.out.println("Merge cost: " + MERGE_COST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithFinnInputList() {
|
||||
List<Integer> numbers = List.of(new Integer[] {24, 25, 26, 27, 28, 21, 22, 23, 18, 19, 20, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 3, 1, 2});
|
||||
|
||||
powerSort(numbers);
|
||||
System.out.println("Result: ");
|
||||
System.out.println(new ArrayList<>(List.of(numbers)));
|
||||
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package de.uni_marburg.powersort.msort;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.uni_marburg.powersort.msort.IMPL_M_1.MERGE_COST;
|
||||
import static de.uni_marburg.powersort.msort.IMPL_M_1.extendRun;
|
||||
import static de.uni_marburg.powersort.msort.IMPL_M_1.fillWithAscRunsHighToLow;
|
||||
import static de.uni_marburg.powersort.msort.IMPL_M_1.powerSort;
|
||||
|
||||
class PowerSortTest {
|
||||
@Test
|
||||
|
||||
public void testWithOneInputList() {
|
||||
List<Integer> list = new ArrayList<>(List.of(5, 2, 8, 12, 1, 6));
|
||||
extendRun(list, 0);
|
||||
System.out.println(list);
|
||||
// example from slides he wrote this
|
||||
int[] runs = {5, 3, 3, 14, 1, 2};
|
||||
// runs = new int[]{9, 16, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
|
||||
|
||||
List<Integer> a = new ArrayList<>(IntStream.range(0, Arrays.stream(runs).sum()).boxed().collect(Collectors.toList()));
|
||||
|
||||
System.out.println();
|
||||
fillWithAscRunsHighToLow(a, runs, 1);
|
||||
MERGE_COST = 0;
|
||||
System.out.println("Sorting with Powersort:");
|
||||
powerSort(a);
|
||||
System.out.println("Merge cost: " + MERGE_COST);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user