APL/DEV 2.3/Sorting/Tests.java
2022-06-13 16:26:56 +02:00

46 lines
1.3 KiB
Java

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.util.Arrays;
public class Tests {
@Test
public void testOrdered() {
double[] arr = Sorting.sort(new double[] {5.225, 2592.2 ,218.1, 2952895828528.1, 11.2, -25.1});
for (int i = 1; i < arr.length; i++) {
assertTrue(arr[i] >= arr[i-1]);
}
}
@Test
public void testSorted() {
double[] arr = new double[] {3.2, 589.2, 28582.1, 4.285824, 6.5282};
double[] sortedArr = new double[] {3.2, 4.285824, 6.5282, 589.2, 28582.1};
System.out.println(Arrays.toString(sortedArr));
System.out.println(Arrays.toString(Sorting.sort(arr)));
assertTrue(Arrays.equals(sortedArr, Sorting.sort(arr)));
}
@Test
public void testZeroOneElementTable() {
Sorting.sort(new double[] {});
Sorting.sort(new double[] {1});
}
@Test
public void testAlreadySorted() {
double[] arr = new double[] {1.5, 2.7, 3.82, 5.5, 189.22};
assertTrue(Arrays.equals(arr, Sorting.sort(arr)));
}
@Test(expected = NullPointerException.class)
public void testNullTable() {
Sorting.sort(null);
}
}