FindSums { public List<Pair<Integer, Integer>> findLinearComplexityOrder(int[] numbers, int n) { validateInput(numbers); List<Pair<Integer, Integer>> sums = new LinkedList<Pair<Integer, Integer>>(); Map<Integer, Integer> partialElements = new HashMap<Integer, Integer>(); for (int number : numbers) { if (partialElements.containsKey(number)) { sums.add(new Pair<Integer, Integer>(number, partialElements.get(number))); } else { partialElements.put(n - number, number); } } 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 shouldNotAcceptNullArraysLinear() { findSums.findLinearComplexityOrder(null, 2); }
@Test public void shouldReturnAnEmptyResultIfTheArrayIsEmptyLinear() { int[] inputArray = { }; List<Pair<Integer, Integer>> result = findSums.findLinearComplexityOrder(inputArray, 3); assertTrue(result.isEmpty()); }
@Test public void shouldFindEveryPairLinear() { int[] inputArray = { 5, 2, 6, 1, 9 }; int inputValue = 7; List<Pair<Integer, Integer>> result = findSums.findLinearComplexityOrder(inputArray, inputValue); assertTrue(result.contains(new Pair<Integer, Integer>(2, 5))); assertTrue(result.contains(new Pair<Integer, Integer>(1, 6))); }
@Test public void shouldWorkWithNegativeIntegersAsInputLinear() { int[] inputArray = { 5, 2, -17, 6, 1, 9 }; int inputValue = -8; List<Pair<Integer, Integer>> result = findSums.findLinearComplexityOrder(inputArray, inputValue); assertTrue(result.contains(new Pair<Integer, Integer>(9, -17))); }