diff options
Diffstat (limited to 'model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuter.java')
-rw-r--r-- | model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuter.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuter.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuter.java new file mode 100644 index 00000000..0f7b4642 --- /dev/null +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/smoke/utils/TestPermuter.java | |||
@@ -0,0 +1,46 @@ | |||
1 | package org.eclipse.viatra.solver.data.map.tests.smoke.utils; | ||
2 | |||
3 | import java.util.LinkedList; | ||
4 | import java.util.List; | ||
5 | import java.util.stream.Stream; | ||
6 | |||
7 | import org.junit.jupiter.params.provider.Arguments; | ||
8 | |||
9 | public class TestPermuter { | ||
10 | static List<List<Object>> permutationInternal(int from, Object[]... valueOption) { | ||
11 | if (valueOption.length == from) { | ||
12 | return List.of(List.of()); | ||
13 | } else { | ||
14 | Object[] permuteThis = valueOption[from]; | ||
15 | List<List<Object>> otherCombination = permutationInternal(from + 1, valueOption); | ||
16 | List<List<Object>> result = new LinkedList<>(); | ||
17 | for (Object permuteThisElement : permuteThis) { | ||
18 | for (List<Object> otherCombinationList : otherCombination) { | ||
19 | List<Object> newResult = new LinkedList<>(); | ||
20 | newResult.add(permuteThisElement); | ||
21 | newResult.addAll(otherCombinationList); | ||
22 | result.add(newResult); | ||
23 | } | ||
24 | } | ||
25 | return result; | ||
26 | } | ||
27 | } | ||
28 | |||
29 | public static Stream<Arguments> permutation(Object[]... valueOption) { | ||
30 | List<List<Object>> permutations = permutationInternal(0, valueOption); | ||
31 | return permutations.stream().map(x -> Arguments.of(x.toArray())); | ||
32 | } | ||
33 | |||
34 | public static Stream<Arguments> permutationWithSize(Object[]... valueOption) { | ||
35 | int size = 1; | ||
36 | for (int i = 0; i < valueOption.length; i++) { | ||
37 | size *= valueOption[i].length; | ||
38 | } | ||
39 | Object[][] newValueOption = new Object[valueOption.length + 1][]; | ||
40 | newValueOption[0] = new Object[] { size }; | ||
41 | for (int i = 1; i < newValueOption.length; i++) { | ||
42 | newValueOption[i] = valueOption[i - 1]; | ||
43 | } | ||
44 | return permutation(newValueOption); | ||
45 | } | ||
46 | } | ||