aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects
diff options
context:
space:
mode:
authorLibravatar nagilooh <ficsorattila96@gmail.com>2023-08-24 18:57:39 +0200
committerLibravatar nagilooh <ficsorattila96@gmail.com>2023-08-24 18:57:39 +0200
commit7411385e4aef631376a5b647e9bc1b27f625a964 (patch)
tree1c99e0f18c93f305412f8536df23824dd89cc1db /subprojects
parentMerge pull request #37 from nagilooh/design-space-exploration (diff)
downloadrefinery-7411385e4aef631376a5b647e9bc1b27f625a964.tar.gz
refinery-7411385e4aef631376a5b647e9bc1b27f625a964.tar.zst
refinery-7411385e4aef631376a5b647e9bc1b27f625a964.zip
Add new transformation rule actions
- TransformationActions can be created after creating the model - equivalence of actions can be checked
Diffstat (limited to 'subprojects')
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/DesignSpaceExplorationAdapter.java3
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java7
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java7
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java51
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java11
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java27
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java65
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java40
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java93
-rw-r--r--subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java391
10 files changed, 695 insertions, 0 deletions
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/DesignSpaceExplorationAdapter.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/DesignSpaceExplorationAdapter.java
index 5aed5298..ab87ddd5 100644
--- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/DesignSpaceExplorationAdapter.java
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/DesignSpaceExplorationAdapter.java
@@ -6,6 +6,7 @@
6package tools.refinery.store.dse; 6package tools.refinery.store.dse;
7 7
8import tools.refinery.store.adapter.ModelAdapter; 8import tools.refinery.store.adapter.ModelAdapter;
9import tools.refinery.store.dse.internal.TransformationRule;
9import tools.refinery.store.map.Version; 10import tools.refinery.store.map.Version;
10import tools.refinery.store.dse.internal.Activation; 11import tools.refinery.store.dse.internal.Activation;
11import tools.refinery.store.dse.internal.DesignSpaceExplorationBuilderImpl; 12import tools.refinery.store.dse.internal.DesignSpaceExplorationBuilderImpl;
@@ -65,4 +66,6 @@ public interface DesignSpaceExplorationAdapter extends ModelAdapter {
65 public void setRandom(long seed); 66 public void setRandom(long seed);
66 67
67 public List<Version> getSolutions(); 68 public List<Version> getSolutions();
69
70 void addTransformationRule(TransformationRule transformationRule);
68} 71}
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java
index 220f0b2d..0a5cd7fc 100644
--- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java
@@ -13,6 +13,7 @@ import tools.refinery.store.map.Version;
13import tools.refinery.store.model.Interpretation; 13import tools.refinery.store.model.Interpretation;
14import tools.refinery.store.model.Model; 14import tools.refinery.store.model.Model;
15import tools.refinery.store.query.ModelQueryAdapter; 15import tools.refinery.store.query.ModelQueryAdapter;
16import tools.refinery.store.query.dnf.Query;
16import tools.refinery.store.query.dnf.RelationalQuery; 17import tools.refinery.store.query.dnf.RelationalQuery;
17import tools.refinery.store.dse.DesignSpaceExplorationAdapter; 18import tools.refinery.store.dse.DesignSpaceExplorationAdapter;
18import tools.refinery.store.dse.DesignSpaceExplorationStoreAdapter; 19import tools.refinery.store.dse.DesignSpaceExplorationStoreAdapter;
@@ -77,6 +78,12 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration
77 78
78 } 79 }
79 80
81 @Override
82 public void addTransformationRule(TransformationRule rule) {
83 transformationRules.add(rule);
84 rule.prepare(model, queryEngine);
85 }
86
80 public List<Version> getTrajectory() { 87 public List<Version> getTrajectory() {
81 return new ArrayList<>(trajectory); 88 return new ArrayList<>(trajectory);
82 } 89 }
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java
new file mode 100644
index 00000000..a63f60f0
--- /dev/null
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java
@@ -0,0 +1,7 @@
1package tools.refinery.store.dse.internal.action;
2
3import tools.refinery.store.tuple.Tuple;
4
5public abstract class ActionSymbol implements AtomicAction {
6 public abstract Tuple getValue(Tuple activation);
7}
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java
new file mode 100644
index 00000000..181a5020
--- /dev/null
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java
@@ -0,0 +1,51 @@
1package tools.refinery.store.dse.internal.action;
2
3import tools.refinery.store.model.Model;
4import tools.refinery.store.tuple.Tuple;
5
6public class ActivationSymbol extends ActionSymbol {
7
8 private final int index;
9 private Tuple value = null;
10
11 public ActivationSymbol() {
12 this(0);
13 }
14
15 public ActivationSymbol(int index) {
16 this.index = index;
17 }
18
19 @Override
20 public void fire(Tuple activation) {
21 value = Tuple.of(activation.get(index));
22 }
23
24 @Override
25 public ActivationSymbol prepare(Model model) {
26 return this;
27 }
28
29 @Override
30 public Tuple getValue(Tuple activation) {
31 return value;
32 }
33
34 @Override
35 public boolean equals(Object obj) {
36 if (obj == this) {
37 return true;
38 }
39 if (!(obj instanceof ActivationSymbol)) {
40 return false;
41 }
42 return index == ((ActivationSymbol) obj).index;
43 }
44
45 @Override
46 public int hashCode() {
47 int result = 17;
48 result = 31 * result + Integer.hashCode(index);
49 return result;
50 }
51}
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java
new file mode 100644
index 00000000..19de644a
--- /dev/null
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java
@@ -0,0 +1,11 @@
1package tools.refinery.store.dse.internal.action;
2
3import tools.refinery.store.model.Model;
4import tools.refinery.store.tuple.Tuple;
5
6public interface AtomicAction {
7
8 void fire(Tuple activation);
9
10 AtomicAction prepare(Model model);
11}
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java
new file mode 100644
index 00000000..589a33c4
--- /dev/null
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java
@@ -0,0 +1,27 @@
1package tools.refinery.store.dse.internal.action;
2
3import tools.refinery.store.dse.DesignSpaceExplorationAdapter;
4import tools.refinery.store.model.Model;
5import tools.refinery.store.tuple.Tuple;
6
7public class DeleteAction implements AtomicAction {
8
9 private final ActionSymbol symbol;
10 private DesignSpaceExplorationAdapter dseAdapter;
11
12 public DeleteAction(ActionSymbol symbol) {
13 this.symbol = symbol;
14 }
15
16 @Override
17 public void fire(Tuple activation) {
18 dseAdapter.deleteObject(symbol.getValue(activation));
19 }
20
21
22 @Override
23 public DeleteAction prepare(Model model) {
24 dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class);
25 return this;
26 }
27}
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java
new file mode 100644
index 00000000..5c02bd45
--- /dev/null
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java
@@ -0,0 +1,65 @@
1package tools.refinery.store.dse.internal.action;
2
3import tools.refinery.store.model.Interpretation;
4import tools.refinery.store.model.Model;
5import tools.refinery.store.tuple.Tuple;
6
7import java.util.Arrays;
8
9public class InsertAction<T> implements AtomicAction {
10
11 private final Interpretation<T> interpretation;
12 private final T value;
13
14 private final ActionSymbol[] symbols;
15
16 public InsertAction(Interpretation<T> interpretation, T value, ActionSymbol... symbols) {
17 this.interpretation = interpretation;
18 this.value = value;
19 this.symbols = symbols;
20
21 }
22
23 @Override
24 public void fire(Tuple activation) {
25 var tuple = Tuple.of(Arrays.stream(symbols).map(symbol -> symbol.getValue(activation).get(0))
26 .mapToInt(Integer::intValue).toArray());
27
28 interpretation.put(tuple, value);
29 }
30
31 @Override
32 public InsertAction<T> prepare(Model model) {
33 return this;
34 }
35
36 public ActionSymbol[] getSymbols() {
37 return symbols;
38 }
39
40 @Override
41 public boolean equals(Object obj) {
42 if (obj == this) {
43 return true;
44 }
45 if (!(obj instanceof InsertAction<?> other)) {
46 return false;
47 }
48 if (symbols.length != other.symbols.length) {
49 return false;
50 }
51 if (!interpretation.equals(other.interpretation)) {
52 return false;
53 }
54 return value.equals(other.value);
55 }
56
57 @Override
58 public int hashCode() {
59 int result = 17;
60 result = 31 * result + Integer.hashCode(symbols.length);
61 result = 31 * result + interpretation.hashCode();
62 result = 31 * result + value.hashCode();
63 return result;
64 }
65}
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java
new file mode 100644
index 00000000..3c69b9a0
--- /dev/null
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java
@@ -0,0 +1,40 @@
1package tools.refinery.store.dse.internal.action;
2
3import tools.refinery.store.dse.DesignSpaceExplorationAdapter;
4import tools.refinery.store.model.Model;
5import tools.refinery.store.tuple.Tuple;
6import tools.refinery.store.tuple.Tuple1;
7
8public class NewItemSymbol extends ActionSymbol {
9 private DesignSpaceExplorationAdapter dseAdapter;
10 private Tuple1 value;
11
12 @Override
13 public void fire(Tuple activation) {
14 value = dseAdapter.createObject();
15 }
16
17 @Override
18 public NewItemSymbol prepare(Model model) {
19 dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class);
20 return this;
21 }
22
23 @Override
24 public Tuple1 getValue(Tuple activation) {
25 return value;
26 }
27
28 @Override
29 public boolean equals(Object obj) {
30 if (obj == this) {
31 return true;
32 }
33 return obj instanceof NewItemSymbol;
34 }
35
36 @Override
37 public int hashCode() {
38 return 42;
39 }
40}
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java
new file mode 100644
index 00000000..2e58a8c4
--- /dev/null
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java
@@ -0,0 +1,93 @@
1package tools.refinery.store.dse.internal.action;
2
3import tools.refinery.store.model.Model;
4import tools.refinery.store.tuple.Tuple;
5import tools.refinery.store.tuple.Tuple2;
6
7import java.util.*;
8
9public class TransformationAction {
10 private final List<ActionSymbol> actionSymbols = new ArrayList<>();
11 private final List<InsertAction<?>> insertActions = new ArrayList<>();
12 private boolean configured = false;
13 private final Map<Integer, List<Tuple2>> activationSymbolUsageMap = new LinkedHashMap<>();
14
15 public TransformationAction add(ActionSymbol action) {
16 checkConfigured();
17 actionSymbols.add(action);
18 return this;
19 }
20
21 public TransformationAction add(InsertAction<?> action) {
22 checkConfigured();
23 insertActions.add(action);
24 return this;
25 }
26
27 private void checkConfigured() {
28 if (configured) {
29 throw new IllegalStateException("Action already configured.");
30 }
31 }
32
33 public TransformationAction prepare(Model model) {
34 for (ActionSymbol action : actionSymbols) {
35 action.prepare(model);
36 }
37 for (InsertAction<?> action : insertActions) {
38 action.prepare(model);
39 }
40
41 for (var insertAction : insertActions) {
42 var actionIndex = insertActions.indexOf(insertAction);
43 var symbols = insertAction.getSymbols();
44 for (var i = 0; i < symbols.length; i++) {
45 var symbolGlobalIndex = actionSymbols.indexOf(symbols[i]);
46 activationSymbolUsageMap.computeIfAbsent(symbolGlobalIndex, k -> new ArrayList<>());
47 activationSymbolUsageMap.get(symbolGlobalIndex).add(Tuple.of(actionIndex, i));
48 }
49 }
50
51 configured = true;
52 return this;
53 }
54
55 public boolean fire(Tuple activation) {
56 for (ActionSymbol action : actionSymbols) {
57 action.fire(activation);
58 }
59 for (InsertAction<?> action : insertActions) {
60 action.fire(activation);
61 }
62 return true;
63 }
64
65 // True if Symbols and InsertActions are inserted in same order, ActivationSymbols are equal (they have the same
66 // index for getting the value from the activation Tuple) and InsertActions are equal (they have the same arity
67 // and value to be set).
68 @Override
69 public boolean equals(Object obj) {
70 if (obj == this) {
71 return true;
72 }
73 if (!(obj instanceof TransformationAction other)) {
74 return false;
75 }
76 if (!actionSymbols.equals(other.actionSymbols)) {
77 return false;
78 }
79 if (!insertActions.equals(other.insertActions)) {
80 return false;
81 }
82 return this.activationSymbolUsageMap.equals(other.activationSymbolUsageMap);
83
84 }
85
86 @Override
87 public int hashCode() {
88 var result = 17;
89 result = 31 * result + actionSymbols.hashCode();
90 result = 31 * result + insertActions.hashCode();
91 return result;
92 }
93}
diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java
new file mode 100644
index 00000000..d54bc7d3
--- /dev/null
+++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java
@@ -0,0 +1,391 @@
1package tools.refinery.store.dse;
2
3import org.junit.jupiter.api.BeforeAll;
4import org.junit.jupiter.api.Test;
5import tools.refinery.store.dse.internal.action.*;
6import tools.refinery.store.dse.strategy.DepthFirstStrategy;
7import tools.refinery.store.model.Model;
8import tools.refinery.store.model.ModelStore;
9import tools.refinery.store.query.dnf.Query;
10import tools.refinery.store.query.dnf.RelationalQuery;
11import tools.refinery.store.query.viatra.ViatraModelQueryAdapter;
12import tools.refinery.store.query.view.AnySymbolView;
13import tools.refinery.store.query.view.KeyOnlyView;
14import tools.refinery.store.representation.Symbol;
15import tools.refinery.store.representation.TruthValue;
16
17import static org.junit.jupiter.api.Assertions.assertEquals;
18import static org.junit.jupiter.api.Assertions.assertNotEquals;
19
20public class ActionEqualsTest {
21
22 private static Model model;
23 private static DesignSpaceExplorationAdapter dseAdapter;
24 private static Symbol<Boolean> type1;
25 private static Symbol<Boolean> type2;
26 private static Symbol<TruthValue> type3;
27 private static Symbol<Boolean> relation1;
28 private static Symbol<Boolean> relation2;
29 private static RelationalQuery precondition1;
30 private static RelationalQuery precondition2;
31
32 @BeforeAll
33 public static void init() {
34 type1 = Symbol.of("type1", 1);
35 type2 = Symbol.of("type2", 1);
36 type3 = Symbol.of("type3", 1, TruthValue.class);
37 relation1 = Symbol.of("relation1", 2);
38 relation2 = Symbol.of("relation2", 2);
39 AnySymbolView type1View = new KeyOnlyView<>(type1);
40 precondition1 = Query.of("CreateClassPrecondition",
41 (builder, model) -> builder.clause(
42 type1View.call(model)
43 ));
44
45 precondition2 = Query.of("CreateFeaturePrecondition",
46 (builder, model) -> builder.clause(
47 type1View.call(model)
48 ));
49 var store = ModelStore.builder()
50 .symbols(type1, type2, type3, relation2, relation1)
51 .with(ViatraModelQueryAdapter.builder()
52 .queries(precondition1, precondition2))
53 .with(DesignSpaceExplorationAdapter.builder()
54 .strategy(new DepthFirstStrategy()))
55 .build();
56
57
58
59 model = store.createEmptyModel();
60 dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class);
61 }
62
63 @Test
64 void emptyActionEqualsTest() {
65 var action1 = new TransformationAction();
66 var action2 = new TransformationAction();
67 assertEquals(action1, action1);
68 assertEquals(action2, action2);
69 assertEquals(action1, action2);
70 }
71
72 @Test
73 void actionTrivialTest() {
74 var newItemSymbol1 = new NewItemSymbol();
75 var activationSymbol = new ActivationSymbol();
76 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
77 activationSymbol);
78 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
79 activationSymbol);
80
81 var action1 = new TransformationAction();
82 action1.add(newItemSymbol1);
83 action1.add(activationSymbol);
84 action1.add(insertAction1);
85 action1.prepare(model);
86
87 var action2 = new TransformationAction();
88 action2.add(newItemSymbol1);
89 action2.add(activationSymbol);
90 action2.add(insertAction2);
91 action2.prepare(model);
92
93 assertEquals(action1, action2);
94 }
95
96 @Test
97 void actionIdenticalTest() {
98 var newItemSymbol1 = new NewItemSymbol();
99 var activationSymbol1 = new ActivationSymbol();
100 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, activationSymbol1);
101
102 var action1 = new TransformationAction();
103 action1.add(newItemSymbol1);
104 action1.add(activationSymbol1);
105 action1.add(insertAction1);
106 action1.prepare(model);
107
108
109 var newItemSymbol2 = new NewItemSymbol();
110 var activationSymbol2 = new ActivationSymbol();
111 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2,
112 activationSymbol2);
113
114 var action2 = new TransformationAction();
115 action2.add(newItemSymbol2);
116 action2.add(activationSymbol2);
117 action2.add(insertAction2);
118 action2.prepare(model);
119
120 assertEquals(action1, action2);
121 }
122
123 @Test
124 void actionSymbolGlobalOrderTest() {
125 var newItemSymbol1 = new NewItemSymbol();
126 var activationSymbol1 = new ActivationSymbol();
127 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, activationSymbol1);
128
129 var action1 = new TransformationAction();
130 action1.add(newItemSymbol1);
131 action1.add(activationSymbol1);
132 action1.add(insertAction1);
133 action1.prepare(model);
134
135
136 var newItemSymbol2 = new NewItemSymbol();
137 var activationSymbol2 = new ActivationSymbol();
138 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2,
139 activationSymbol2);
140
141 var action2 = new TransformationAction();
142 action2.add(activationSymbol2);
143 action2.add(newItemSymbol2);
144 action2.add(insertAction2);
145 action2.prepare(model);
146
147 assertNotEquals(action1, action2);
148 }
149
150 @Test
151 void actionSymbolInInsertActionOrderTest() {
152 var newItemSymbol1 = new NewItemSymbol();
153 var activationSymbol1 = new ActivationSymbol();
154 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, activationSymbol1);
155
156 var action1 = new TransformationAction();
157 action1.add(newItemSymbol1);
158 action1.add(activationSymbol1);
159 action1.add(insertAction1);
160 action1.prepare(model);
161
162
163 var newItemSymbol2 = new NewItemSymbol();
164 var activationSymbol2 = new ActivationSymbol();
165 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, activationSymbol2,
166 newItemSymbol2);
167
168 var action2 = new TransformationAction();
169 action2.add(newItemSymbol2);
170 action2.add(activationSymbol2);
171 action2.add(insertAction2);
172 action2.prepare(model);
173
174 assertNotEquals(action1, action2);
175 }
176
177 @Test
178 void identicalInsertActionInDifferentOrderTest() {
179 var newItemSymbol1 = new NewItemSymbol();
180 var activationSymbol1 = new ActivationSymbol();
181 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
182 activationSymbol1);
183 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
184 activationSymbol1);
185
186 var action1 = new TransformationAction();
187 action1.add(newItemSymbol1);
188 action1.add(activationSymbol1);
189 action1.add(insertAction1);
190 action1.add(insertAction2);
191 action1.prepare(model);
192
193 var action2 = new TransformationAction();
194 action2.add(newItemSymbol1);
195 action2.add(activationSymbol1);
196 action2.add(insertAction2);
197 action2.add(insertAction1);
198 action2.prepare(model);
199
200 assertEquals(action1, action2);
201 }
202
203 @Test
204 void identicalActionAndSymbolDifferentOrderTest() {
205 var newItemSymbol1 = new NewItemSymbol();
206 var activationSymbol1 = new ActivationSymbol();
207 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
208 activationSymbol1);
209
210 var newItemSymbol2 = new NewItemSymbol();
211 var activationSymbol2 = new ActivationSymbol();
212 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2,
213 activationSymbol2);
214
215 var action1 = new TransformationAction();
216 action1.add(newItemSymbol1);
217 action1.add(newItemSymbol2);
218 action1.add(activationSymbol1);
219 action1.add(activationSymbol2);
220 action1.add(insertAction1);
221 action1.add(insertAction2);
222 action1.prepare(model);
223
224 var action2 = new TransformationAction();
225 action2.add(newItemSymbol2);
226 action2.add(newItemSymbol1);
227 action2.add(activationSymbol2);
228 action2.add(activationSymbol1);
229 action2.add(insertAction2);
230 action2.add(insertAction1);
231 action2.prepare(model);
232
233 assertEquals(action1, action2);
234 }
235
236 @Test
237 void identicalActionAndSymbolMixedOrderTest() {
238 var newItemSymbol1 = new NewItemSymbol();
239 var activationSymbol1 = new ActivationSymbol();
240 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
241 activationSymbol1);
242
243 var newItemSymbol2 = new NewItemSymbol();
244 var activationSymbol2 = new ActivationSymbol();
245 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2,
246 activationSymbol2);
247
248 var action1 = new TransformationAction();
249 action1.add(newItemSymbol1);
250 action1.add(newItemSymbol2);
251 action1.add(activationSymbol1);
252 action1.add(activationSymbol2);
253 action1.add(insertAction1);
254 action1.add(insertAction2);
255 action1.prepare(model);
256
257 var action2 = new TransformationAction();
258 action2.add(insertAction1);
259 action2.add(newItemSymbol1);
260 action2.add(newItemSymbol2);
261 action2.add(activationSymbol1);
262 action2.add(insertAction2);
263 action2.add(activationSymbol2);
264 action2.prepare(model);
265
266 assertEquals(action1, action2);
267 }
268
269 @Test
270 void insertActionInterpretationTest() {
271 var newItemSymbol1 = new NewItemSymbol();
272 var activationSymbol1 = new ActivationSymbol();
273 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
274 activationSymbol1);
275 var insertAction2 = new InsertAction<>(model.getInterpretation(type2), true, newItemSymbol1,
276 activationSymbol1);
277
278 var action1 = new TransformationAction();
279 action1.add(newItemSymbol1);
280 action1.add(activationSymbol1);
281 action1.add(insertAction1);
282 action1.prepare(model);
283
284 var action2 = new TransformationAction();
285 action2.add(newItemSymbol1);
286 action2.add(activationSymbol1);
287 action2.add(insertAction2);
288 action2.prepare(model);
289
290 assertNotEquals(action1, action2);
291 }
292
293 @Test
294 void insertActionValueTest() {
295 var newItemSymbol1 = new NewItemSymbol();
296 var activationSymbol1 = new ActivationSymbol();
297 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
298 activationSymbol1);
299 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol1,
300 activationSymbol1);
301
302 var action1 = new TransformationAction();
303 action1.add(newItemSymbol1);
304 action1.add(activationSymbol1);
305 action1.add(insertAction1);
306 action1.prepare(model);
307
308 var action2 = new TransformationAction();
309 action2.add(newItemSymbol1);
310 action2.add(activationSymbol1);
311 action2.add(insertAction2);
312 action2.prepare(model);
313
314 assertNotEquals(action1, action2);
315 }
316
317 @Test
318 void newItemSymbolDuplicateTest() {
319 var newItemSymbol1 = new NewItemSymbol();
320 var newItemSymbol2 = new NewItemSymbol();
321 var activationSymbol1 = new ActivationSymbol();
322 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
323 activationSymbol1);
324 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2,
325 activationSymbol1);
326
327 var action1 = new TransformationAction();
328 action1.add(newItemSymbol1);
329 action1.add(activationSymbol1);
330 action1.add(insertAction1);
331 action1.prepare(model);
332
333 var action2 = new TransformationAction();
334 action2.add(newItemSymbol2);
335 action2.add(activationSymbol1);
336 action2.add(insertAction2);
337 action2.prepare(model);
338
339 assertEquals(action1, action2);
340 }
341
342 @Test
343 void activationSymbolDuplicateTest() {
344 var newItemSymbol1 = new NewItemSymbol();
345 var activationSymbol1 = new ActivationSymbol();
346 var activationSymbol2 = new ActivationSymbol();
347 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
348 activationSymbol1);
349 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
350 activationSymbol2);
351
352 var action1 = new TransformationAction();
353 action1.add(newItemSymbol1);
354 action1.add(activationSymbol1);
355 action1.add(insertAction1);
356 action1.prepare(model);
357
358 var action2 = new TransformationAction();
359 action2.add(newItemSymbol1);
360 action2.add(activationSymbol2);
361 action2.add(insertAction2);
362 action2.prepare(model);
363
364 assertEquals(action1, action2);
365 }
366
367 @Test
368 void activationSymbolIndexTest() {
369 var newItemSymbol1 = new NewItemSymbol();
370 var activationSymbol1 = new ActivationSymbol(0);
371 var activationSymbol2 = new ActivationSymbol(1);
372 var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
373 activationSymbol1);
374 var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1,
375 activationSymbol2);
376
377 var action1 = new TransformationAction();
378 action1.add(newItemSymbol1);
379 action1.add(activationSymbol1);
380 action1.add(insertAction1);
381 action1.prepare(model);
382
383 var action2 = new TransformationAction();
384 action2.add(newItemSymbol1);
385 action2.add(activationSymbol2);
386 action2.add(insertAction2);
387 action2.prepare(model);
388
389 assertNotEquals(action1, action2);
390 }
391}