@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))); }
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; }
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; } }
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; }  }
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); }
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);  }