Problem4_2 { public static IntPair minimize_sorted(int[] sorted) { int diff = sorted[1] - sorted[0]; IntPair pair = null; for (int i = 1; i < sorted.length - 1; i++) { int first = sorted[i]; int second = sorted[i + 1]; if (diff > (second - first)) { diff = second - first; pair = new IntPair(first, second); } } return pair; }  static IntPair maximize_unsorted(int[] numbers); static IntPair maximize_sorted(int[] numbers); static IntPair minimize_unsorted(int[] numbers); static IntPair minimize_sorted(int[] sorted);  }
@Test public void shouldFindPairThatMinimiseWithinSortedArray() throws Exception { int[] numbers = {3, 6, 8, 13, 19}; IntPair p = Problem4_2.minimize_sorted(numbers); assertThat(p, equalTo(new IntPair(6, 8))); }