comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TestHelper.java @ 11464:e55e24cc3e7b

Truffle-DSL: added permutation util functions to the TestHelper.
author Christian Humer <christian.humer@gmail.com>
date Thu, 29 Aug 2013 14:28:32 +0200
parents c7d9ff67beed
children 88316d1c4644
comparison
equal deleted inserted replaced
11445:5fbd1ba4a5f3 11464:e55e24cc3e7b
73 73
74 static <E> Object executeWith(TestRootNode<? extends ValueNode> node, Object... values) { 74 static <E> Object executeWith(TestRootNode<? extends ValueNode> node, Object... values) {
75 return createCallTarget(node).call(new TestArguments(values)); 75 return createCallTarget(node).call(new TestArguments(values));
76 } 76 }
77 77
78 static Object array(Object... val) {
79 return val;
80 }
81
82 static <E> List<List<E>> permutations(List<E> list) {
83 return permutations(new ArrayList<E>(), list, new ArrayList<List<E>>());
84 }
85
86 static Object[][] permutations(Object... list) {
87 List<List<Object>> permutations = permutations(Arrays.asList(list));
88
89 Object[][] a = new Object[permutations.size()][];
90 int index = 0;
91 for (List<Object> p : permutations) {
92 a[index] = p.toArray(new Object[p.size()]);
93 index++;
94 }
95
96 return a;
97 }
98
99 static <E> List<List<E>> permutations(List<E> prefix, List<E> suffix, List<List<E>> output) {
100 if (suffix.size() == 1) {
101 ArrayList<E> newElement = new ArrayList<>(prefix);
102 newElement.addAll(suffix);
103 output.add(newElement);
104 return output;
105 }
106
107 for (int i = 0; i < suffix.size(); i++) {
108 List<E> newPrefix = new ArrayList<>(prefix);
109 newPrefix.add(suffix.get(i));
110 List<E> newSuffix = new ArrayList<>(suffix);
111 newSuffix.remove(i);
112 permutations(newPrefix, newSuffix, output);
113 }
114
115 return output;
116 }
117
78 } 118 }