### Question:
TwoSum { public static boolean solve(int[] arr, int tar) { LSDRadixSorter sorter = new LSDRadixSorter(); sorter.sort(arr); int i = 0, j = arr.length - 1; while (i <= j) { long cur = (long) arr[i] + arr[j]; if (cur > tar) j--; else if (cur < tar) i++; else return true; } return false; }  static boolean solve(int[] arr, int tar);  }### Answer:
@Test public void overflowTest() { boolean test = TwoSum.solve(new int[]{Integer.MAX_VALUE, Integer.MAX_VALUE}, -2); assertEquals(false, test); assertEquals(true, TwoSum.solve(new int[]{-1, Integer.MIN_VALUE, Integer.MAX_VALUE}, -1)); }
@Test public void noAnsTest() { boolean test = TwoSum.solve(new int[]{}, -2); assertEquals(false, test); test = TwoSum.solve(new int[]{-2}, -2); assertEquals(false, test); test = TwoSum.solve(new int[]{-3, -4, -5}, -2); assertEquals(false, test); }
@Test public void haveAnsTest() { boolean test = TwoSum.solve(new int[]{0, 0}, 0); assertEquals(true, test); test = TwoSum.solve(new int[]{1, 1, 3, 4}, 2); assertEquals(true, test); test = TwoSum.solve(new int[]{-3, -4, -5}, -8); assertEquals(true, test); }
@Test public void randomTest() { int N = 10000; for (int i = 0; i < 500; i++) { if (i % 100 == 99) N <<= 1; int[] arr = Shuffler.getRandomArray(N, -N, N); Assert.assertEquals(expect(arr, 0), TwoSum.solve(arr, 0)); System.out.println("pass " + N); } }