From 0b3f95bbc05d74b37d7c769bf76f38c25e4b1b73 Mon Sep 17 00:00:00 2001 From: nagilooh Date: Fri, 25 Aug 2023 17:04:43 +0200 Subject: Move equivalence checking to new method Also: - Rename Symbol to Variable - Make fire for InsertAction with low arity faster --- .../store/dse/internal/action/ActionSymbol.java | 7 - .../store/dse/internal/action/ActionVariable.java | 7 + .../dse/internal/action/ActivationSymbol.java | 59 ----- .../dse/internal/action/ActivationVariable.java | 49 ++++ .../store/dse/internal/action/AtomicAction.java | 2 + .../store/dse/internal/action/DeleteAction.java | 25 +- .../store/dse/internal/action/InsertAction.java | 69 +++--- .../store/dse/internal/action/NewItemSymbol.java | 48 ---- .../store/dse/internal/action/NewItemVariable.java | 40 ++++ .../dse/internal/action/TransformationAction.java | 76 ++++--- .../tools/refinery/store/dse/ActionEqualsTest.java | 253 ++++++++++----------- 11 files changed, 317 insertions(+), 318 deletions(-) delete mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java delete mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java delete mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java 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 deleted file mode 100644 index a63f60f0..00000000 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java +++ /dev/null @@ -1,7 +0,0 @@ -package tools.refinery.store.dse.internal.action; - -import tools.refinery.store.tuple.Tuple; - -public abstract class ActionSymbol implements AtomicAction { - public abstract Tuple getValue(Tuple activation); -} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java new file mode 100644 index 00000000..51078d15 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java @@ -0,0 +1,7 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.tuple.Tuple; + +public interface ActionVariable extends AtomicAction { + Tuple getValue(); +} 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 deleted file mode 100644 index 7598de0a..00000000 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java +++ /dev/null @@ -1,59 +0,0 @@ -package tools.refinery.store.dse.internal.action; - -import tools.refinery.store.model.Model; -import tools.refinery.store.tuple.Tuple; - -public class ActivationSymbol extends ActionSymbol { - - private final int index; - private Tuple value; - - public ActivationSymbol() { - this(0); - } - - public ActivationSymbol(int index) { - this.index = index; - } - - @Override - public void fire(Tuple activation) { - value = Tuple.of(activation.get(index)); - } - - @Override - public ActivationSymbol prepare(Model model) { - return this; - } - - @Override - public Tuple getValue(Tuple activation) { - return value; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof ActivationSymbol other)) { - return false; - } - - if (index != other.index) { - return false; - } - if (value == null) { - return other.value == null; - } - return value.equals(other.value); - } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + Integer.hashCode(index); - result = 31 * result + value.hashCode(); - return result; - } -} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java new file mode 100644 index 00000000..148d4156 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java @@ -0,0 +1,49 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.model.Model; +import tools.refinery.store.tuple.Tuple; + +public class ActivationVariable implements ActionVariable { + + private final int index; + private Tuple value; + + public ActivationVariable() { + this(0); + } + + public ActivationVariable(int index) { + this.index = index; + } + + @Override + public void fire(Tuple activation) { + value = Tuple.of(activation.get(index)); + } + + @Override + public ActivationVariable prepare(Model model) { + return this; + } + + @Override + public Tuple getValue() { + return value; + } + + @Override + public boolean equalsWithSubstitution(AtomicAction other) { + if (other == null || getClass() != other.getClass()) { + return false; + } + var otherAction = (ActivationVariable) other; + + if (index != otherAction.index) { + return false; + } + if (value == null) { + return otherAction.value == null; + } + return value.equals(otherAction.value); + } +} 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 index 19de644a..470278ae 100644 --- 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 @@ -8,4 +8,6 @@ public interface AtomicAction { void fire(Tuple activation); AtomicAction prepare(Model model); + + boolean equalsWithSubstitution(AtomicAction other); } 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 index c7cc4600..9fa77df3 100644 --- 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 @@ -6,16 +6,16 @@ import tools.refinery.store.tuple.Tuple; public class DeleteAction implements AtomicAction { - private final ActionSymbol symbol; + private final ActionVariable variable; private DesignSpaceExplorationAdapter dseAdapter; - public DeleteAction(ActionSymbol symbol) { - this.symbol = symbol; + public DeleteAction(ActionVariable variable) { + this.variable = variable; } @Override public void fire(Tuple activation) { - dseAdapter.deleteObject(symbol.getValue(activation)); + dseAdapter.deleteObject(variable.getValue()); } @Override @@ -25,20 +25,11 @@ public class DeleteAction implements AtomicAction { } @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof DeleteAction other)) { + public boolean equalsWithSubstitution(AtomicAction other) { + if (other == null || getClass() != other.getClass()) { return false; } - return this.symbol.getClass() == other.symbol.getClass(); - } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + symbol.getClass().hashCode(); - return result; + var otherAction = (DeleteAction) other; + return this.variable.getClass() == otherAction.variable.getClass(); } } 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 index 7adab93b..2335abad 100644 --- 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 @@ -3,6 +3,7 @@ package tools.refinery.store.dse.internal.action; import tools.refinery.store.model.Interpretation; import tools.refinery.store.model.Model; import tools.refinery.store.tuple.Tuple; +import tools.refinery.store.tuple.Tuple0; import java.util.Arrays; @@ -10,21 +11,42 @@ public class InsertAction implements AtomicAction { private final Interpretation interpretation; private final T value; + private final int arity; + private final ActionVariable[] variables; - private final ActionSymbol[] symbols; - - public InsertAction(Interpretation interpretation, T value, ActionSymbol... symbols) { + public InsertAction(Interpretation interpretation, T value, ActionVariable... variables) { this.interpretation = interpretation; this.value = value; - this.symbols = symbols; - + this.variables = variables; + this.arity = interpretation.getSymbol().arity(); + if (variables.length != arity) { + throw new IllegalArgumentException("Expected " + arity + " variables, but got " + variables.length); + } } @Override public void fire(Tuple activation) { - var tuple = Tuple.of(Arrays.stream(symbols).map(symbol -> symbol.getValue(activation).get(0)) - .mapToInt(Integer::intValue).toArray()); + Tuple tuple; + if (arity == 0) { + tuple = Tuple0.INSTANCE; + } + else if (arity == 1) { + tuple = variables[0].getValue(); + } + else if (arity == 2) { + tuple = Tuple.of(variables[0].getValue().get(0), variables[1].getValue().get(0)); + } + else if (arity == 3) { + tuple = Tuple.of(variables[0].getValue().get(0), variables[1].getValue().get(0), variables[2].getValue().get(0)); + } + else { + tuple = Tuple.of(Arrays.stream(variables).map(variable -> variable.getValue().get(0)) + .mapToInt(Integer::intValue).toArray()); + } + interpretation.put(tuple, value); + } + public void put(Tuple tuple) { interpretation.put(tuple, value); } @@ -33,46 +55,35 @@ public class InsertAction implements AtomicAction { return this; } - public ActionSymbol[] getSymbols() { - return symbols; + public ActionVariable[] getVariables() { + return variables; } @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof InsertAction other)) { + public boolean equalsWithSubstitution(AtomicAction other) { + if (other == null || getClass() != other.getClass()) { return false; } - if (symbols.length != other.symbols.length) { + var otherAction = (InsertAction) other; + if (variables.length != otherAction.variables.length) { return false; } - if (!interpretation.equals(other.interpretation)) { + if (!interpretation.equals(otherAction.interpretation)) { return false; } if (value == null) { - if (other.value != null) { + if (otherAction.value != null) { return false; } } - else if (!value.equals(other.value)) { + else if (!value.equals(otherAction.value)) { return false; } - for (var i = 0; i < symbols.length; i++) { - if (!symbols[i].equals(other.symbols[i])) { + for (var i = 0; i < variables.length; i++) { + if (!variables[i].equalsWithSubstitution(otherAction.variables[i])) { return false; } } return true; } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + Arrays.hashCode(symbols); - result = 31 * result + interpretation.hashCode(); - result = 31 * result + value.hashCode(); - return result; - } } 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 deleted file mode 100644 index acdc3cae..00000000 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java +++ /dev/null @@ -1,48 +0,0 @@ -package tools.refinery.store.dse.internal.action; - -import tools.refinery.store.dse.DesignSpaceExplorationAdapter; -import tools.refinery.store.model.Model; -import tools.refinery.store.tuple.Tuple; -import tools.refinery.store.tuple.Tuple1; - -public class NewItemSymbol extends ActionSymbol { - private DesignSpaceExplorationAdapter dseAdapter; - private Tuple1 value; - - @Override - public void fire(Tuple activation) { - value = dseAdapter.createObject(); - } - - @Override - public NewItemSymbol prepare(Model model) { - dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); - return this; - } - - @Override - public Tuple1 getValue(Tuple activation) { - return value; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof NewItemSymbol other)) { - return false; - } - if (value == null) { - return other.value == null; - } - return value.equals(other.value); - } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + value.hashCode(); - return result; - } -} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java new file mode 100644 index 00000000..65b1f544 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java @@ -0,0 +1,40 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.dse.DesignSpaceExplorationAdapter; +import tools.refinery.store.model.Model; +import tools.refinery.store.tuple.Tuple; +import tools.refinery.store.tuple.Tuple1; + +public class NewItemVariable implements ActionVariable { + private DesignSpaceExplorationAdapter dseAdapter; + private Tuple1 value; + + @Override + public void fire(Tuple activation) { + value = dseAdapter.createObject(); + } + + @Override + public NewItemVariable prepare(Model model) { + dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); + return this; + } + + @Override + public Tuple1 getValue() { + return value; + } + + @Override + public boolean equalsWithSubstitution(AtomicAction other) { + if (other == null || getClass() != other.getClass()) { + return false; + } + var otherAction = (NewItemVariable) other; + if (value == null) { + return otherAction.value == null; + } + return value.equals(otherAction.value); + + } +} 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 index 19ab4575..50387f53 100644 --- 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 @@ -7,15 +7,15 @@ import tools.refinery.store.tuple.Tuple2; import java.util.*; public class TransformationAction { - private final List actionSymbols = new ArrayList<>(); + private final List actionVariables = new ArrayList<>(); private final List> insertActions = new ArrayList<>(); private final List deleteActions = new ArrayList<>(); private boolean configured = false; - private final Map> activationSymbolUsageMap = new LinkedHashMap<>(); + private final Map> actionVariableUsageMap = new LinkedHashMap<>(); - public TransformationAction add(ActionSymbol action) { + public TransformationAction add(ActionVariable action) { checkConfigured(); - actionSymbols.add(action); + actionVariables.add(action); return this; } @@ -38,7 +38,7 @@ public class TransformationAction { } public TransformationAction prepare(Model model) { - for (ActionSymbol action : actionSymbols) { + for (ActionVariable action : actionVariables) { action.prepare(model); } for (InsertAction action : insertActions) { @@ -50,11 +50,11 @@ public class TransformationAction { for (var insertAction : insertActions) { var actionIndex = insertActions.indexOf(insertAction); - var symbols = insertAction.getSymbols(); - for (var i = 0; i < symbols.length; i++) { - var symbolGlobalIndex = actionSymbols.indexOf(symbols[i]); - activationSymbolUsageMap.computeIfAbsent(symbolGlobalIndex, k -> new ArrayList<>()); - activationSymbolUsageMap.get(symbolGlobalIndex).add(Tuple.of(actionIndex, i)); + var variables = insertAction.getVariables(); + for (var i = 0; i < variables.length; i++) { + var variablelGlobalIndex = actionVariables.indexOf(variables[i]); + actionVariableUsageMap.computeIfAbsent(variablelGlobalIndex, k -> new ArrayList<>()); + actionVariableUsageMap.get(variablelGlobalIndex).add(Tuple.of(actionIndex, i)); } } @@ -63,7 +63,7 @@ public class TransformationAction { } public boolean fire(Tuple activation) { - for (ActionSymbol action : actionSymbols) { + for (ActionVariable action : actionVariables) { action.fire(activation); } for (InsertAction action : insertActions) { @@ -75,36 +75,50 @@ public class TransformationAction { return true; } - // True if Symbols and InsertActions are inserted in same order, ActivationSymbols are equal (they have the same - // index for getting the value from the activation Tuple) and InsertActions are equal (they have the same arity - // and value to be set). - @Override - public boolean equals(Object obj) { - if (obj == this) { + // Returns true if ActionVariables and InsertActions are inserted in same order, ActionVariables are equal (they + // have the same index for getting the value from the activation Tuple) and InsertActions are equal (they have + // the same arity and value to be set). + public boolean equalsWithSubstitution(TransformationAction other) { + if (other == this) { return true; } - if (!(obj instanceof TransformationAction other)) { + + if (actionVariables.size() != other.actionVariables.size()) { return false; } - if (!actionSymbols.equals(other.actionSymbols)) { + + if (insertActions.size() != other.insertActions.size()) { return false; } - if (!insertActions.equals(other.insertActions)) { + + if (deleteActions.size() != other.deleteActions.size()) { return false; } - if (!deleteActions.equals(other.deleteActions)) { - return false; + + for (var i = 0; i < actionVariables.size(); i++) { + var variable = actionVariables.get(i); + var otherVariable = other.actionVariables.get(i); + if (!variable.equalsWithSubstitution(otherVariable)) { + return false; + } } - return this.activationSymbolUsageMap.equals(other.activationSymbolUsageMap); - } + for (var i = 0; i < insertActions.size(); i++) { + var insertAction = insertActions.get(i); + var otherInsertAction = other.insertActions.get(i); + if (!insertAction.equalsWithSubstitution(otherInsertAction)) { + return false; + } + } + + for (var i = 0; i < deleteActions.size(); i++) { + var deleteAction = deleteActions.get(i); + var otherDeleteAction = other.deleteActions.get(i); + if (!deleteAction.equalsWithSubstitution(otherDeleteAction)) { + return false; + } + } + return this.actionVariableUsageMap.equals(other.actionVariableUsageMap); - @Override - public int hashCode() { - var result = 17; - result = 31 * result + actionSymbols.hashCode(); - result = 31 * result + insertActions.hashCode(); - result = 31 * result + deleteActions.hashCode(); - return result; } } 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 index e29260e9..1489b413 100644 --- 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 @@ -14,8 +14,7 @@ import tools.refinery.store.query.view.KeyOnlyView; import tools.refinery.store.representation.Symbol; import tools.refinery.store.representation.TruthValue; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.*; public class ActionEqualsTest { @@ -55,7 +54,6 @@ public class ActionEqualsTest { .build(); - model = store.createEmptyModel(); dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); } @@ -64,40 +62,46 @@ public class ActionEqualsTest { void emptyActionEqualsTest() { var action1 = new TransformationAction(); var action2 = new TransformationAction(); - assertEquals(action1, action1); - assertEquals(action2, action2); - assertEquals(action1, action2); + + assertTrue(action1.equalsWithSubstitution(action1)); + assertTrue(action2.equalsWithSubstitution(action2)); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void actionTrivialTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var insertAction3 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1); + var insertAction4 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol); var action1 = new TransformationAction(); action1.add(newItemSymbol1); action1.add(activationSymbol); action1.add(insertAction1); + action1.add(insertAction2); action1.prepare(model); var action2 = new TransformationAction(); action2.add(newItemSymbol1); action2.add(activationSymbol); - action2.add(insertAction2); + action2.add(insertAction3); + action2.add(insertAction4); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void actionIdenticalTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, activationSymbol1); + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, + activationSymbol1); var action1 = new TransformationAction(); action1.add(newItemSymbol1); @@ -105,10 +109,9 @@ public class ActionEqualsTest { action1.add(insertAction1); action1.prepare(model); - - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var action2 = new TransformationAction(); @@ -117,14 +120,14 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void actionSymbolGlobalOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); var action1 = new TransformationAction(); @@ -133,10 +136,9 @@ public class ActionEqualsTest { action1.add(insertAction1); action1.prepare(model); - - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var action2 = new TransformationAction(); @@ -145,43 +147,39 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test - void actionSymbolInInsertActionOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, activationSymbol1); + void actionSymbolRepeatedInInsertActionTest() { + var newItemSymbol1 = new NewItemVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, + newItemSymbol1); var action1 = new TransformationAction(); action1.add(newItemSymbol1); - action1.add(activationSymbol1); action1.add(insertAction1); action1.prepare(model); - - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, activationSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, newItemSymbol2); var action2 = new TransformationAction(); action2.add(newItemSymbol2); - action2.add(activationSymbol2); action2.add(insertAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void identicalInsertActionInDifferentOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); var action1 = new TransformationAction(); @@ -198,19 +196,20 @@ public class ActionEqualsTest { action2.add(insertAction1); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void identicalActionAndSymbolDifferentOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var activationSymbol2 = new ActivationVariable(); + + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var action1 = new TransformationAction(); @@ -231,19 +230,19 @@ public class ActionEqualsTest { action2.add(insertAction1); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void identicalActionAndSymbolMixedOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var action1 = new TransformationAction(); @@ -264,16 +263,16 @@ public class ActionEqualsTest { action2.add(activationSymbol2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void insertActionInterpretationTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type2), true, newItemSymbol1, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation2), true, newItemSymbol1, activationSymbol1); var action1 = new TransformationAction(); @@ -288,16 +287,16 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void insertActionValueTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol1, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol1, activationSymbol1); var action1 = new TransformationAction(); @@ -312,17 +311,17 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void newItemSymbolDuplicateTest() { - var newItemSymbol1 = new NewItemSymbol(); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol1); var action1 = new TransformationAction(); @@ -337,17 +336,17 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void activationSymbolDuplicateTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol2); var action1 = new TransformationAction(); @@ -362,17 +361,17 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void activationSymbolIndexTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(0); - var activationSymbol2 = new ActivationSymbol(1); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(0); + var activationSymbol2 = new ActivationVariable(1); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol2); var action1 = new TransformationAction(); @@ -387,14 +386,14 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void deleteActionTest() { - var newItemSymbol = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(0); - var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + var newItemSymbol = new NewItemVariable(); + var activationSymbol = new ActivationVariable(0); + var insertAction = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol, activationSymbol); var deleteAction = new DeleteAction(activationSymbol); @@ -412,14 +411,14 @@ public class ActionEqualsTest { action2.add(deleteAction); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void deleteActionMissingTest() { - var newItemSymbol = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(0); - var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + var newItemSymbol = new NewItemVariable(); + var activationSymbol = new ActivationVariable(0); + var insertAction = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol, activationSymbol); var deleteAction = new DeleteAction(activationSymbol); @@ -436,14 +435,14 @@ public class ActionEqualsTest { action2.add(insertAction); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void deleteActionIdenticalTest() { - var newItemSymbol = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(0); - var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + var newItemSymbol = new NewItemVariable(); + var activationSymbol = new ActivationVariable(0); + var insertAction = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol, activationSymbol); var deleteAction1 = new DeleteAction(activationSymbol); var deleteAction2 = new DeleteAction(activationSymbol); @@ -462,14 +461,14 @@ public class ActionEqualsTest { action2.add(deleteAction2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void deleteActionSymbolTypeTest() { - var newItemSymbol = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(0); - var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + var newItemSymbol = new NewItemVariable(); + var activationSymbol = new ActivationVariable(0); + var insertAction = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol, activationSymbol); var deleteAction1 = new DeleteAction(activationSymbol); var deleteAction2 = new DeleteAction(newItemSymbol); @@ -488,14 +487,14 @@ public class ActionEqualsTest { action2.add(deleteAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void deleteActionOrderTest() { - var newItemSymbol = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(0); - var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + var newItemSymbol = new NewItemVariable(); + var activationSymbol = new ActivationVariable(0); + var insertAction = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol, activationSymbol); var deleteAction1 = new DeleteAction(activationSymbol); var deleteAction2 = new DeleteAction(newItemSymbol); @@ -516,20 +515,20 @@ public class ActionEqualsTest { action2.add(deleteAction1); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void actionsMixedOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); var deleteAction1 = new DeleteAction(newItemSymbol1); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var deleteAction2 = new DeleteAction(activationSymbol2); @@ -555,20 +554,20 @@ public class ActionEqualsTest { action2.add(activationSymbol2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void twoUnpreparedActionsTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); var deleteAction1 = new DeleteAction(newItemSymbol1); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var deleteAction2 = new DeleteAction(activationSymbol2); @@ -592,20 +591,20 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.add(activationSymbol2); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void oneUnpreparedActionTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); var deleteAction1 = new DeleteAction(newItemSymbol1); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var deleteAction2 = new DeleteAction(activationSymbol2); @@ -630,6 +629,6 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.add(activationSymbol2); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } } -- cgit v1.2.3-54-g00ecf