FindSums { public List<Pair<Integer, Integer>> find(int[] numbers, int value) { validateInput(numbers); List<Pair<Integer, Integer>> sums = new LinkedList<Pair<Integer, Integer>>(); for (int i = 0; i < numbers.length; i++) { for (int j = 0; j < numbers.length; j++) { if (numbers[i] + numbers[j] == value) { sums.add(new Pair(numbers[i], numbers[j])); } } } return sums; }  List<Pair<Integer, Integer>> find(int[] numbers, int value); List<Pair<Integer, Integer>> findLinearComplexityOrder(int[] numbers, int n);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullArrays() { findSums.find(null, 2); }
@Test public void shouldReturnAnEmptyResultIfTheArrayIsEmpty() { int[] inputArray = { }; List<Pair<Integer, Integer>> result = findSums.find(inputArray, 3); assertTrue(result.isEmpty()); }
@Test public void shouldFindEveryPair() { int[] inputArray = { 5, 2, 6, 1, 9 }; int inputValue = 7; List<Pair<Integer, Integer>> result = findSums.find(inputArray, inputValue); assertTrue(result.contains(new Pair<Integer, Integer>(5, 2))); assertTrue(result.contains(new Pair<Integer, Integer>(6, 1))); }
@Test public void shouldWorkWithNegativeIntegersAsInput() { int[] inputArray = { 5, 2, -17, 6, 1, 9 }; int inputValue = -8; List<Pair<Integer, Integer>> result = findSums.find(inputArray, inputValue); assertTrue(result.contains(new Pair<Integer, Integer>(-17, 9))); }