| 1 | import java.util.Arrays; |
| 2 | |
| 3 | public class ArraysTest { |
| 4 | private static void expect(boolean v) { |
| 5 | if (! v) throw new RuntimeException(); |
| 6 | } |
| 7 | |
| 8 | private static <T extends Comparable<T>> void expectSorted(T[] array) { |
| 9 | for (int i = 1; i < array.length; ++i) { |
| 10 | expect(array[i - 1].compareTo(array[i]) <= 0); |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | private static int pseudoRandom(int seed) { |
| 15 | return 3170425 * seed + 132102; |
| 16 | } |
| 17 | |
| 18 | private static <T extends Comparable<T>> int shuffle(T[] array, int seed) { |
| 19 | for (int i = array.length; i > 1; --i) { |
| 20 | int i2 = (seed < 0 ? -seed : seed) % i; |
| 21 | T value = array[i - 1]; |
| 22 | array[i - 1] = array[i2]; |
| 23 | array[i2] = value; |
| 24 | seed = pseudoRandom(seed); |
| 25 | } |
| 26 | return seed; |
| 27 | } |
| 28 | |
| 29 | public static void testSort() { |
| 30 | Integer[] array = new Integer[64]; |
| 31 | for (int i = 0; i < array.length; ++i) { |
| 32 | array[i] = Integer.valueOf(i + 1); |
| 33 | } |
| 34 | ; |
| 35 | int random = 12345; |
| 36 | for (int i = 0; i < 32; ++i) { |
| 37 | random = shuffle(array, random); |
| 38 | Arrays.sort(array); |
| 39 | expectSorted(array); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | public static void main(String[] args) { |
| 44 | { int[] array = new int[0]; |
| 45 | Exception exception = null; |
| 46 | try { |
| 47 | int x = array[0]; |
| 48 | } catch (ArrayIndexOutOfBoundsException e) { |
| 49 | exception = e; |
| 50 | } |
| 51 | |
| 52 | expect(exception != null); |
| 53 | } |
| 54 | |
| 55 | { int[] array = new int[0]; |
| 56 | Exception exception = null; |
| 57 | try { |
| 58 | int x = array[-1]; |
| 59 | } catch (ArrayIndexOutOfBoundsException e) { |
| 60 | exception = e; |
nothing calls this directly
no outgoing calls
no test coverage detected