Hi guys , i wrote some junit tests for my mergesort class, but i don't know how to write a test for a array with 100 000 Element , any Idea?
<pre>
What I have tried:
<pre lang="java"><pre>p
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import de.hska.iwi.ads.sorting.Sort;
import java.util.Arrays;
public class MergesortTest extends SortTest {
@Override
public <E extends Comparable<E>> Sort<E> createSort() {
return new Mergesort<E>();
}
@Test
void testMergesortInteger() {
Integer[] a = { 2, 1, 7, 12, 5, 9, 8, 10 };
Integer[] result = { 1, 2, 5, 7, 8, 9, 10, 12 };
Mergesort<Integer> ms = new Mergesort<Integer>();
ms.sort(a);
assertTrue(Arrays.equals(a, result));
}
@Test
void testMergesortInteger1() {
Integer[] a = { 5, 2, 1, 2, 5, 4, 2 };
Integer[] result = { 1, 2, 2, 2, 4, 5, 5 };
Mergesort<Integer> ms = new Mergesort<Integer>();
ms.sort(a);
assertTrue(Arrays.equals(a, result));
}
@Test
void testMergesortString() {
String[] a = { "r", "a", "b", "d" };
String[] result = { "a", "b", "d", "r" };
Mergesort<String> ms = new Mergesort<String>();
ms.sort(a);
assertTrue(Arrays.equals(a, result));
}
@Test
void testMergesortString1() {
String[] a = { "baby", "a", "king", "to", "music", "blue" };
String[] result = { "a", "baby", "blue", "king", "music", "to" };
Mergesort<String> ms = new Mergesort<String>();
ms.sort(a);
assertTrue(Arrays.equals(a, result));
}
@Test
void testMergesortIntArrayIntNull() {
Integer[] a = null;
Mergesort<Integer> ms = new Mergesort<Integer>();
assertThrows(NullPointerException.class, () -> ms.sort(a));
}
@Test
void testMergesortOneElement() {
Integer[] a = { 5 };
Integer[] result = { 5 };
Mergesort<Integer> ms = new Mergesort<Integer>();
ms.sort(a);
assertTrue(Arrays.equals(a, result));
}
@Test
void testMergesortTwoElement() {
Integer[] a = { 5, 3 };
Integer[] result = { 3, 5 };
Mergesort<Integer> ms = new Mergesort<Integer>();
ms.sort(a);
assertTrue(Arrays.equals(a, result));
}