Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TestHelper.java @ 11880:9a747d8e0d0f
broadened types in Canonicalizable interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 01 Oct 2013 20:32:47 +0200 |
parents | 1ccb36a32f87 |
children | 85dcc7f59c34 |
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 |
11469
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
25 import static org.junit.Assert.*; |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
26 |
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
|
27 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
|
28 |
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.*; |
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.*; |
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.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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 |
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 * 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
|
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 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
|
42 |
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 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
|
44 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
|
45 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
|
46 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
|
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 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
|
49 } |
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 |
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 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
|
52 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
|
53 |
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 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
|
55 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
|
56 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
|
57 } 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
|
58 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
|
59 } |
11191
c7d9ff67beed
Truffle-DSL: Fixed argument order problem for test cases.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
60 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
|
61 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
|
62 } |
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 |
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 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
|
65 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
|
66 } |
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 |
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 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
|
69 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
|
70 } |
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 |
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 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
|
73 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
|
74 } |
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 |
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 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
|
77 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
|
78 } |
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
|
79 |
11464
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
80 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
|
81 return val; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
82 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
83 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
84 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
|
85 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
|
86 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
87 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
88 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
|
89 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
|
90 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
91 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
|
92 int index = 0; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
93 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
|
94 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
|
95 index++; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
96 } |
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 return a; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
99 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
100 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
101 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
|
102 if (suffix.size() == 1) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
103 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
|
104 newElement.addAll(suffix); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
105 output.add(newElement); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
106 return output; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
107 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
108 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 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
|
113 newSuffix.remove(i); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
114 permutations(newPrefix, newSuffix, output); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
115 } |
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 return output; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
118 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
119 |
11469
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
120 /* Methods tests all test values in combinational order. */ |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
121 static void assertRuns(NodeFactory<? extends ValueNode> factory, Object result, Object... testValues) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
122 // test each run by its own. |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
123 for (int i = 0; i < testValues.length; i++) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
124 assertValue(createRoot(factory), result, testValues); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
125 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
126 |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
127 // test all combinations of the test values |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
128 List<List<Object>> permuts = permutations(Arrays.asList(testValues)); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
129 for (List<Object> list : permuts) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
130 TestRootNode<?> root = createRoot(factory); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
131 for (Object object : list) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
132 assertValue(root, result, object); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
133 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
134 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
135 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
136 |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
137 static void assertValue(TestRootNode<? extends ValueNode> root, Object result, Object testValues) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
138 if (testValues instanceof Object[]) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
139 assertEquals(result, executeWith(root, (Object[]) testValues)); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
140 } else { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
141 assertEquals(result, executeWith(root, testValues)); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
142 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
143 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
144 |
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
|
145 } |