@Test public void shouldReturnEveryCombinationOfChange() { int[] moneys = { 5, 10, 15, 50 }; List<List<Integer>> combinations = combinationsOfChange.get(moneys, 60); assertContainsChange(combinations, new Integer[] { 50, 10 }, new Integer[] { 15, 15, 15, 15 }, new Integer[] { 10, 10, 10, 10, 10, 10 }, new Integer[] { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }); }
public List<List<Integer>> get(int[] availableChange, int value) { validateInputData(availableChange, value); List<List<Integer>> changeCombinations = new LinkedList<List<Integer>>(); for (int i = 0; i < availableChange.length; i++) { int[] availableMoneys = Arrays.copyOfRange(availableChange, 0, availableChange.length - i); List<Integer> change = getChange(availableMoneys, value); changeCombinations.add(change); } return changeCombinations; }
CombinationsOfChange { public List<List<Integer>> get(int[] availableChange, int value) { validateInputData(availableChange, value); List<List<Integer>> changeCombinations = new LinkedList<List<Integer>>(); for (int i = 0; i < availableChange.length; i++) { int[] availableMoneys = Arrays.copyOfRange(availableChange, 0, availableChange.length - i); List<Integer> change = getChange(availableMoneys, value); changeCombinations.add(change); } return changeCombinations; } }
CombinationsOfChange { public List<List<Integer>> get(int[] availableChange, int value) { validateInputData(availableChange, value); List<List<Integer>> changeCombinations = new LinkedList<List<Integer>>(); for (int i = 0; i < availableChange.length; i++) { int[] availableMoneys = Arrays.copyOfRange(availableChange, 0, availableChange.length - i); List<Integer> change = getChange(availableMoneys, value); changeCombinations.add(change); } return changeCombinations; } CombinationsOfChange(); }
CombinationsOfChange { public List<List<Integer>> get(int[] availableChange, int value) { validateInputData(availableChange, value); List<List<Integer>> changeCombinations = new LinkedList<List<Integer>>(); for (int i = 0; i < availableChange.length; i++) { int[] availableMoneys = Arrays.copyOfRange(availableChange, 0, availableChange.length - i); List<Integer> change = getChange(availableMoneys, value); changeCombinations.add(change); } return changeCombinations; } CombinationsOfChange(); List<List<Integer>> get(int[] availableChange, int value); }
CombinationsOfChange { public List<List<Integer>> get(int[] availableChange, int value) { validateInputData(availableChange, value); List<List<Integer>> changeCombinations = new LinkedList<List<Integer>>(); for (int i = 0; i < availableChange.length; i++) { int[] availableMoneys = Arrays.copyOfRange(availableChange, 0, availableChange.length - i); List<Integer> change = getChange(availableMoneys, value); changeCombinations.add(change); } return changeCombinations; } CombinationsOfChange(); List<List<Integer>> get(int[] availableChange, int value);  }