forked from Hithomelabs/Princeton1
44 lines
1.2 KiB
Java
44 lines
1.2 KiB
Java
package com.hithomelabs.princeton1.module6;
|
|
|
|
import com.hithomelabs.princeton1.module5.ComparableSort;
|
|
import com.hithomelabs.princeton1.common.Apple;
|
|
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 java.util.ArrayList;
|
|
import java.util.Random;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class MergeTest {
|
|
|
|
private ComparableSort<Apple> sortingAlgorithm;
|
|
private ArrayList<Apple> apples;
|
|
private Random random;
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
apples = new ArrayList<>();
|
|
random = new Random();
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Merge Sort test client")
|
|
public void testSort(){
|
|
sortingAlgorithm = new Merge<Apple>();
|
|
for(int i = 0; i < 10; i++)
|
|
apples.add(new Apple(random.nextInt(100)));
|
|
Apple[] arr = apples.toArray(new Apple[apples.size()]);
|
|
apples.sort(null);
|
|
Apple[] sorted = apples.toArray(new Apple[apples.size()]);
|
|
sortingAlgorithm.sort(arr);
|
|
assertArrayEquals(sorted, arr);
|
|
}
|
|
|
|
@AfterEach
|
|
void tearDown() {
|
|
sortingAlgorithm = null;
|
|
}
|
|
} |