forked from Hithomelabs/Princeton1
56 lines
1.4 KiB
Java
56 lines
1.4 KiB
Java
package com.hithomelabs.princeton1.module5;
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
import com.hithomelabs.princeton1.common.Apple;
|
|
import java.util.ArrayList;
|
|
import java.util.Random;
|
|
|
|
class SortTest {
|
|
|
|
private ArrayList<Apple> apples;
|
|
private AbstractCustomSorts<Apple> sortingAlgorithm;
|
|
private Random random;
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
apples = new ArrayList<Apple>();
|
|
//sortingAlgorithm = new Selection<Apple>();
|
|
random = new Random();
|
|
}
|
|
|
|
private void testSort(AbstractCustomSorts<Apple> sortingAlgorithm) {
|
|
for (int i = 0; i < 100; i++)
|
|
apples.add(new Apple(random.nextInt(100)));
|
|
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Testing Insertion sort functionality")
|
|
public void testInsertionSort() {
|
|
sortingAlgorithm = new Insertion<Apple>();
|
|
testSort(sortingAlgorithm);
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Testing Selection sort functionality")
|
|
public void testSelectionSort() {
|
|
sortingAlgorithm = new Selection<Apple>();
|
|
testSort(sortingAlgorithm);
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Testing Shell sort functionality")
|
|
public void testShellSort() {
|
|
sortingAlgorithm = new Shell<>();
|
|
testSort(sortingAlgorithm);
|
|
}
|
|
|
|
@AfterEach
|
|
void tearDown() {
|
|
sortingAlgorithm = null;
|
|
apples = null;
|
|
}
|
|
} |