import java.util.Arrays; import java.util.Random; public class ReverseTest { public static Random rand = new Random(); /** * requires: - 'array' is not null * ensures: - for each element at position 'i' in 'array', it has the same * value as 'array[array.length - 1 - i]' in the pre-state. **/ public static void reverse(int[] array) { for (int i = 0; i < array.length / 2; i++) { array[i] = array[array.length - i - 1]; array[array.length - i - 1] = array[i]; } } public static int[] generate(int length) { // TODO generate array of specified length. return null; } public static boolean test(int[] array) { try { // TODO check that reversing works // What properties make sense? Note that the reverse works in-place. return false; } catch (Exception e) { e.printStackTrace(); return false; } } public static void main(String[] arg) { for (int i = 0; i < 10000; i++) { int[] array = generate(rand.nextInt(30)); if (!test(array)) { System.out.println("Failed: " + Arrays.toString(array)); System.exit(0); } } System.out.println("Done."); } }