aboutsummaryrefslogtreecommitdiffstats
path: root/language-model/src/testFixtures
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-12 17:48:47 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-12 17:48:47 +0100
commitfc7e9312d00e60171ed77c477ed91231d3dbfff9 (patch)
treecc185dd088b5fa6e9357aab3c9062a70626d1953 /language-model/src/testFixtures
parentbuild: refactor java-application conventions (diff)
downloadrefinery-fc7e9312d00e60171ed77c477ed91231d3dbfff9.tar.gz
refinery-fc7e9312d00e60171ed77c477ed91231d3dbfff9.tar.zst
refinery-fc7e9312d00e60171ed77c477ed91231d3dbfff9.zip
build: move modules into subproject directory
Diffstat (limited to 'language-model/src/testFixtures')
-rw-r--r--language-model/src/testFixtures/java/tools/refinery/language/model/tests/ProblemTestUtil.java197
1 files changed, 0 insertions, 197 deletions
diff --git a/language-model/src/testFixtures/java/tools/refinery/language/model/tests/ProblemTestUtil.java b/language-model/src/testFixtures/java/tools/refinery/language/model/tests/ProblemTestUtil.java
deleted file mode 100644
index d0990dc0..00000000
--- a/language-model/src/testFixtures/java/tools/refinery/language/model/tests/ProblemTestUtil.java
+++ /dev/null
@@ -1,197 +0,0 @@
1package tools.refinery.language.model.tests;
2
3import java.util.List;
4import java.util.stream.Stream;
5
6import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
7import org.eclipse.emf.ecore.util.EcoreUtil;
8
9import tools.refinery.language.model.ProblemUtil;
10import tools.refinery.language.model.problem.ActionLiteral;
11import tools.refinery.language.model.problem.Argument;
12import tools.refinery.language.model.problem.Assertion;
13import tools.refinery.language.model.problem.AssertionArgument;
14import tools.refinery.language.model.problem.Atom;
15import tools.refinery.language.model.problem.ClassDeclaration;
16import tools.refinery.language.model.problem.Conjunction;
17import tools.refinery.language.model.problem.DeleteActionLiteral;
18import tools.refinery.language.model.problem.EnumDeclaration;
19import tools.refinery.language.model.problem.IndividualDeclaration;
20import tools.refinery.language.model.problem.Literal;
21import tools.refinery.language.model.problem.NamedElement;
22import tools.refinery.language.model.problem.NegativeLiteral;
23import tools.refinery.language.model.problem.NewActionLiteral;
24import tools.refinery.language.model.problem.Node;
25import tools.refinery.language.model.problem.NodeAssertionArgument;
26import tools.refinery.language.model.problem.NodeValueAssertion;
27import tools.refinery.language.model.problem.Parameter;
28import tools.refinery.language.model.problem.ParametricDefinition;
29import tools.refinery.language.model.problem.PredicateDefinition;
30import tools.refinery.language.model.problem.Problem;
31import tools.refinery.language.model.problem.ReferenceDeclaration;
32import tools.refinery.language.model.problem.Relation;
33import tools.refinery.language.model.problem.RuleDefinition;
34import tools.refinery.language.model.problem.Statement;
35import tools.refinery.language.model.problem.ValueActionLiteral;
36import tools.refinery.language.model.problem.ValueLiteral;
37import tools.refinery.language.model.problem.Variable;
38import tools.refinery.language.model.problem.VariableOrNode;
39import tools.refinery.language.model.problem.VariableOrNodeArgument;
40
41public class ProblemTestUtil {
42 public Problem builtin(Problem problem) {
43 return ProblemUtil.getBuiltInLibrary(problem).get();
44 }
45
46 public List<Diagnostic> errors(Problem problem) {
47 EcoreUtil.resolveAll(problem);
48 return problem.eResource().getErrors();
49 }
50
51 public List<String> nodeNames(Problem problem) {
52 return problem.getNodes().stream().map(node -> node.getName()).toList();
53 }
54
55 public PredicateDefinition pred(Problem problem, String name) {
56 return namedStatementOfType(problem, PredicateDefinition.class, name);
57 }
58
59 public RuleDefinition rule(Problem problem, String name) {
60 return namedStatementOfType(problem, RuleDefinition.class, name);
61 }
62
63 public Parameter param(ParametricDefinition definition, int i) {
64 return definition.getParameters().get(i);
65 }
66
67 public Conjunction conj(ParametricDefinition definition, int i) {
68 return definition.getBodies().get(i);
69 }
70
71 public Literal lit(Conjunction conjunction, int i) {
72 return conjunction.getLiterals().get(i);
73 }
74
75 public ActionLiteral actionLit(RuleDefinition rule, int i) {
76 return rule.getAction().getActionLiterals().get(i);
77 }
78
79 public Atom valueAtom(Literal literal) {
80 return ((ValueLiteral) literal).getAtom();
81 }
82
83 public Atom negated(Literal literal) {
84 return ((NegativeLiteral) literal).getAtom();
85 }
86
87 public Relation relation(Literal literal) {
88 return ((Atom) literal).getRelation();
89 }
90
91 public Argument arg(Atom atom, int i) {
92 return atom.getArguments().get(i);
93 }
94
95 public Argument arg(Literal literal, int i) {
96 return arg((Atom) literal, i);
97 }
98
99 public VariableOrNode variableOrNode(Argument argument) {
100 return ((VariableOrNodeArgument) argument).getVariableOrNode();
101 }
102
103 public Variable variable(Argument argument) {
104 return (Variable) variableOrNode(argument);
105 }
106
107 public Variable variable(ValueActionLiteral valueActionLiteral, int i) {
108 return variable(arg(valueActionLiteral.getAtom(), i));
109 }
110
111 public Variable variable(NewActionLiteral newActionLiteral) {
112 return newActionLiteral.getVariable();
113 }
114
115 public VariableOrNode deleteVar(ActionLiteral actionLiteral) {
116 return ((DeleteActionLiteral) actionLiteral).getVariableOrNode();
117 }
118
119 public VariableOrNode newVar(ActionLiteral actionLiteral) {
120 return ((NewActionLiteral) actionLiteral).getVariable();
121 }
122
123 public Atom valueAtom(ActionLiteral actionLiteral) {
124 return ((ValueActionLiteral) actionLiteral).getAtom();
125 }
126
127 public Variable variable(DeleteActionLiteral deleteActionLiteral) {
128 return (Variable) deleteActionLiteral.getVariableOrNode();
129 }
130
131 public Node node(Argument argument) {
132 return (Node) variableOrNode(argument);
133 }
134
135 public Assertion assertion(Problem problem, int i) {
136 return nthStatementOfType(problem, Assertion.class, i);
137 }
138
139 public AssertionArgument arg(Assertion assertion, int i) {
140 return assertion.getArguments().get(i);
141 }
142
143 public Node node(AssertionArgument argument) {
144 return ((NodeAssertionArgument) argument).getNode();
145 }
146
147 public Node node(Problem problem, String name) {
148 return named(problem.getNodes(), name);
149 }
150
151 public Node individualNode(Problem problem, String name) {
152 var uniqueNodes = statementsOfType(problem, IndividualDeclaration.class)
153 .flatMap(declaration -> declaration.getNodes().stream());
154 return named(uniqueNodes, name);
155 }
156
157 public NodeValueAssertion nodeValueAssertion(Problem problem, int i) {
158 return nthStatementOfType(problem, NodeValueAssertion.class, i);
159 }
160
161 public ClassDeclaration findClass(Problem problem, String name) {
162 return namedStatementOfType(problem, ClassDeclaration.class, name);
163 }
164
165 public ReferenceDeclaration reference(ClassDeclaration declaration, String name) {
166 return named(declaration.getReferenceDeclarations(), name);
167 }
168
169 public EnumDeclaration findEnum(Problem problem, String name) {
170 return namedStatementOfType(problem, EnumDeclaration.class, name);
171 }
172
173 public Node literal(EnumDeclaration declaration, String name) {
174 return named(declaration.getLiterals(), name);
175 }
176
177 private <T extends NamedElement> T named(Stream<? extends T> stream, String name) {
178 return stream.filter(statement -> name.equals(statement.getName())).findAny().get();
179 }
180
181 private <T extends NamedElement> T named(List<? extends T> list, String name) {
182 return named(list.stream(), name);
183 }
184
185 private <T extends Statement> Stream<T> statementsOfType(Problem problem, Class<? extends T> type) {
186 return problem.getStatements().stream().filter(type::isInstance).map(type::cast);
187 }
188
189 private <T extends Statement & NamedElement> T namedStatementOfType(Problem problem, Class<? extends T> type,
190 String name) {
191 return named(statementsOfType(problem, type), name);
192 }
193
194 private <T extends Statement> T nthStatementOfType(Problem problem, Class<? extends T> type, int n) {
195 return statementsOfType(problem, type).skip(n).findFirst().get();
196 }
197}