Mercurial > hg > truffle
annotate 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 |
rev | line source |
---|---|
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import java.util.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.dsl.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.dsl.test.NodeContainerTest.BuiltinNode; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ArgumentNode; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ChildrenNode; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestArguments; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 /** |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 * Utility class to provide some test helper functions. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 */ |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 class TestHelper { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 private static ArgumentNode[] arguments(int count) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 ArgumentNode[] nodes = new ArgumentNode[count]; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 for (int i = 0; i < nodes.length; i++) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 nodes[i] = new ArgumentNode(i); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 return nodes; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 static <E extends ValueNode> E createNode(NodeFactory<E> factory, Object... constants) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 ArgumentNode[] argumentNodes = arguments(factory.getExecutionSignature().size()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 List<Object> argumentList = new ArrayList<>(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 if (ChildrenNode.class.isAssignableFrom(factory.getNodeClass()) || BuiltinNode.class.isAssignableFrom(factory.getNodeClass())) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 argumentList.add(argumentNodes); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 argumentList.addAll(Arrays.asList(argumentNodes)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 } |
11191
c7d9ff67beed
Truffle-DSL: Fixed argument order problem for test cases.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
58 argumentList.addAll(Arrays.asList(constants)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 return factory.createNode(argumentList.toArray(new Object[argumentList.size()])); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 static <E extends ValueNode> TestRootNode<E> createRoot(NodeFactory<E> factory, Object... constants) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 return new TestRootNode<>(createNode(factory, constants)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 static CallTarget createCallTarget(ValueNode node) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 return createCallTarget(new TestRootNode<>(node)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 static CallTarget createCallTarget(TestRootNode<? extends ValueNode> node) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 return Truffle.getRuntime().createCallTarget(node); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 static <E> Object executeWith(TestRootNode<? extends ValueNode> node, Object... values) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 return createCallTarget(node).call(new TestArguments(values)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 |
11464
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
78 static Object array(Object... val) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
79 return val; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
80 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
81 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
82 static <E> List<List<E>> permutations(List<E> list) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
83 return permutations(new ArrayList<E>(), list, new ArrayList<List<E>>()); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
84 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
85 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
86 static Object[][] permutations(Object... list) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
87 List<List<Object>> permutations = permutations(Arrays.asList(list)); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
88 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
89 Object[][] a = new Object[permutations.size()][]; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
90 int index = 0; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
91 for (List<Object> p : permutations) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
92 a[index] = p.toArray(new Object[p.size()]); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
93 index++; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
94 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
95 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
96 return a; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
97 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
98 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
99 static <E> List<List<E>> permutations(List<E> prefix, List<E> suffix, List<List<E>> output) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
100 if (suffix.size() == 1) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
101 ArrayList<E> newElement = new ArrayList<>(prefix); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
102 newElement.addAll(suffix); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
103 output.add(newElement); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
104 return output; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
105 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
106 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
107 for (int i = 0; i < suffix.size(); i++) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
108 List<E> newPrefix = new ArrayList<>(prefix); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
109 newPrefix.add(suffix.get(i)); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
110 List<E> newSuffix = new ArrayList<>(suffix); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
111 newSuffix.remove(i); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
112 permutations(newPrefix, newSuffix, output); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
113 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
114 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
115 return output; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
116 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
117 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 } |