forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCombinationSumTest.java
More file actions
29 lines (25 loc) · 891 Bytes
/
CombinationSumTest.java
File metadata and controls
29 lines (25 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.thealgorithms.backtracking;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import org.junit.jupiter.api.Test;
class CombinationSumTest {
private static List<List<Integer>> norm(Iterable<List<Integer>> x) {
List<List<Integer>> y = new ArrayList<>();
for (var p : x) {
var q = new ArrayList<>(p);
q.sort(Integer::compare);
y.add(q);
}
y.sort(Comparator.<List<Integer>>comparingInt(List::size).thenComparing(Object::toString));
return y;
}
@Test
void sample() {
int[] candidates = {2, 3, 6, 7};
int target = 7;
var expected = List.of(List.of(2, 2, 3), List.of(7));
assertEquals(norm(expected), norm(CombinationSum.combinationSum(candidates, target)));
}
}