From e22f59b63d78ba993232e331346d151fb58ca764 Mon Sep 17 00:00:00 2001 From: lfrenot <lfrenot@LAPTOP-2HO88BUG.localdomain> Date: Mon, 27 Jun 2022 17:30:30 +0200 Subject: [PATCH] correction commentaires + add/rm/md state et transition --- .../mutation/AddAttributeMutation.java | 2 +- .../mutation/AddMethodMutation.java | 4 +- .../mutation/AddSignalMutation.java | 2 +- .../mutation/AddStateMutation.java | 76 ++++ .../mutation/AddTransitionMutation.java | 99 +++++ .../mutation/AttributeMutation.java | 4 +- .../AvatarStateMachineElementMutation.java | 86 +++++ .../mutation/MdAttributeMutation.java | 6 +- .../mutation/MdMethodMutation.java | 16 +- .../avatartranslator/mutation/MdMutation.java | 2 +- .../mutation/MdSignalMutation.java | 14 +- .../mutation/MdTransitionMutation.java | 174 +++++++++ .../mutation/MethodMutation.java | 2 +- .../mutation/RmAttributeMutation.java | 6 +- .../mutation/RmMethodMutation.java | 8 +- .../avatartranslator/mutation/RmMutation.java | 2 +- .../mutation/RmSignalMutation.java | 8 +- .../mutation/RmStateMutation.java | 63 ++++ .../mutation/RmTransitionMutation.java | 70 ++++ .../mutation/SignalMutation.java | 2 +- .../mutation/StateMutation.java | 68 ++++ .../mutation/TransitionMutation.java | 347 ++++++++++++++++++ .../avatartranslator/AvatarMutationTests.java | 108 ++++++ 23 files changed, 1130 insertions(+), 39 deletions(-) create mode 100644 src/main/java/avatartranslator/mutation/AddStateMutation.java create mode 100644 src/main/java/avatartranslator/mutation/AddTransitionMutation.java create mode 100644 src/main/java/avatartranslator/mutation/AvatarStateMachineElementMutation.java create mode 100644 src/main/java/avatartranslator/mutation/MdTransitionMutation.java create mode 100644 src/main/java/avatartranslator/mutation/RmStateMutation.java create mode 100644 src/main/java/avatartranslator/mutation/RmTransitionMutation.java create mode 100644 src/main/java/avatartranslator/mutation/StateMutation.java create mode 100644 src/main/java/avatartranslator/mutation/TransitionMutation.java diff --git a/src/main/java/avatartranslator/mutation/AddAttributeMutation.java b/src/main/java/avatartranslator/mutation/AddAttributeMutation.java index f5fa57bb89..588edd7ef9 100644 --- a/src/main/java/avatartranslator/mutation/AddAttributeMutation.java +++ b/src/main/java/avatartranslator/mutation/AddAttributeMutation.java @@ -60,7 +60,7 @@ public class AddAttributeMutation extends AttributeMutation implements AddMutati AvatarType type = getType(); AvatarBlock block = getBlock(_avspec); AvatarAttribute aa = new AvatarAttribute(getName(), type, block, null); - if(hasInitialValue()) aa.setInitialValue(getInitialValue()); + if (hasInitialValue()) aa.setInitialValue(getInitialValue()); return aa; } diff --git a/src/main/java/avatartranslator/mutation/AddMethodMutation.java b/src/main/java/avatartranslator/mutation/AddMethodMutation.java index 3429346053..2d63f2b8cd 100644 --- a/src/main/java/avatartranslator/mutation/AddMethodMutation.java +++ b/src/main/java/avatartranslator/mutation/AddMethodMutation.java @@ -63,11 +63,11 @@ public class AddMethodMutation extends MethodMutation implements AddMutation { public AvatarMethod createElement(AvatarSpecification _avspec) { AvatarBlock block = getBlock(_avspec); AvatarMethod am = new AvatarMethod(getName(), null); - for(String s : getReturnParameters()) { + for (String s : getReturnParameters()) { AvatarAttribute aa = new AvatarAttribute("", AvatarType.getType(s), block, null); am.addReturnParameter(aa); } - for(String[] s : getParameters()) { + for (String[] s : getParameters()) { AvatarAttribute aa = new AvatarAttribute(s[1], AvatarType.getType(s[0]), block, null); am.addParameter(aa); } diff --git a/src/main/java/avatartranslator/mutation/AddSignalMutation.java b/src/main/java/avatartranslator/mutation/AddSignalMutation.java index 682e416029..24d0831587 100644 --- a/src/main/java/avatartranslator/mutation/AddSignalMutation.java +++ b/src/main/java/avatartranslator/mutation/AddSignalMutation.java @@ -59,7 +59,7 @@ public class AddSignalMutation extends SignalMutation implements AddMutation { public AvatarSignal createElement(AvatarSpecification _avspec) { AvatarBlock block = getBlock(_avspec); AvatarSignal as = new AvatarSignal(getName(), getInOut(), null); - for(String[] s : getParameters()) { + for (String[] s : getParameters()) { AvatarAttribute aa = new AvatarAttribute(s[1], AvatarType.getType(s[0]), block, null); as.addParameter(aa); } diff --git a/src/main/java/avatartranslator/mutation/AddStateMutation.java b/src/main/java/avatartranslator/mutation/AddStateMutation.java new file mode 100644 index 0000000000..96cdd2e6fc --- /dev/null +++ b/src/main/java/avatartranslator/mutation/AddStateMutation.java @@ -0,0 +1,76 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package avatartranslator.mutation; + +import avatartranslator.*; + +/** + * Class AddStateMutation + * Creation: 27/06/2022 + * + * @author Léon FRENOT + * @version 1.0 27/06/2022 + */ + +public class AddStateMutation extends StateMutation implements AddMutation { + + public AddStateMutation(String _name, String _blockName) { + setName(_name); + setBlockName(_blockName); + } + + //todo : add Graphical referenceObject + private boolean isGraphical = false; + + public AvatarState createElement() { + AvatarState state = new AvatarState(getName(), null); + return state; + + } + + public AvatarState createElement(AvatarSpecification _avspec) { + return createElement(); + } + + public void apply(AvatarSpecification _avspec) { + AvatarStateMachine asm = getAvatarStateMachine(_avspec); + AvatarState state = createElement(); + asm.addElement(state); + } +} diff --git a/src/main/java/avatartranslator/mutation/AddTransitionMutation.java b/src/main/java/avatartranslator/mutation/AddTransitionMutation.java new file mode 100644 index 0000000000..d7496d159a --- /dev/null +++ b/src/main/java/avatartranslator/mutation/AddTransitionMutation.java @@ -0,0 +1,99 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package avatartranslator.mutation; + +import avatartranslator.*; + +import java.util.List; + +/** + * Class AddTransitionMutation + * Creation: 27/06/2022 + * + * @author Léon FRENOT + * @version 1.0 27/06/2022 + */ + +public class AddTransitionMutation extends TransitionMutation implements AddMutation { + + boolean isGraphical = false; + + public AddTransitionMutation(String _blockName) { + setBlockName(_blockName); + initActions(); + } + + //todo : add Graphical referenceObject + public AvatarTransition createElement(AvatarSpecification _avspec) { + AvatarBlock block = getBlock(_avspec); + AvatarTransition trans = new AvatarTransition(block, getName(), null); + if (isProbabilitySet()) { + trans.setProbability(getProbability()); + } + if (isGuardSet()) { + trans.setGuard(getGuard()); + } + if (areDelaysSet()) { + trans.setDelays(getMinDelay(), getMaxDelay()); + } + if (isDelayDistributionLawSet()) { + trans.setDistributionLaw(getDelayDistributionLaw(), getDelayExtra1(), getDelayExtra2()); + } + if (areComputesSet()) { + trans.setComputes(getMinCompute(), getMaxCompute()); + } + List<String> actions = getActions(); + for (String action : actions) { + trans.addAction(action); + } + return trans; + } + + public void apply(AvatarSpecification _avspec) { + AvatarStateMachine asm = getAvatarStateMachine(_avspec); + AvatarTransition trans = createElement(_avspec); + AvatarStateMachineElement fromElement = getFromElement(_avspec); + AvatarStateMachineElement toElement = getToElement(_avspec); + + asm.addElement(trans); + fromElement.addNext(trans); + trans.addNext(toElement); + } + +} diff --git a/src/main/java/avatartranslator/mutation/AttributeMutation.java b/src/main/java/avatartranslator/mutation/AttributeMutation.java index 4b876ed6ac..decc804b78 100644 --- a/src/main/java/avatartranslator/mutation/AttributeMutation.java +++ b/src/main/java/avatartranslator/mutation/AttributeMutation.java @@ -84,11 +84,11 @@ public abstract class AttributeMutation extends BlockStructMutation { } public String getInitialValue() { - if(hasInitialValue()) return initialValue; + if (hasInitialValue()) return initialValue; return null; } - public AvatarAttribute findElement(AvatarSpecification _avspec) { + public AvatarAttribute getElement(AvatarSpecification _avspec) { AvatarBlock block = getBlock(_avspec); return block.getAvatarAttributeWithName(getName()); } diff --git a/src/main/java/avatartranslator/mutation/AvatarStateMachineElementMutation.java b/src/main/java/avatartranslator/mutation/AvatarStateMachineElementMutation.java new file mode 100644 index 0000000000..842c6d8461 --- /dev/null +++ b/src/main/java/avatartranslator/mutation/AvatarStateMachineElementMutation.java @@ -0,0 +1,86 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package avatartranslator.mutation; + +import avatartranslator.*; + +import java.util.List; +import java.util.UUID; + +/** + * Class ASMMutation + * Creation: 27/06/2022 + * + * @author Léon FRENOT + * @version 1.0 27/06/2022 + */ + +public abstract class AvatarStateMachineElementMutation extends BlockStructMutation { + + public static final int UNDEFINED_TYPE = -1; + public static final int NAME_TYPE = 0; + public static final int UUID_TYPE = 1; + + public AvatarStateMachine getAvatarStateMachine(AvatarSpecification _avspec) { + AvatarBlock block = getBlock(_avspec); + return block.getStateMachine(); + } + + public AvatarStateMachineElement getElement(AvatarSpecification _avspec, int _type, String _name) { + AvatarStateMachine asm = getAvatarStateMachine(_avspec); + List<AvatarStateMachineElement> elts = asm.getListOfElements(); + switch(_type) { + case NAME_TYPE: + for (AvatarStateMachineElement elt : elts) { + if (elt.getName().equals(_name)) return elt; + } + return null; + case UUID_TYPE: + for (AvatarStateMachineElement elt : elts) { + UUID eltUUID = elt.getUUID(); + UUID uuid = UUID.fromString(_name); + if (eltUUID != null) { + if (eltUUID.equals(uuid)) return elt; + } + } + return null; + } + return null; + } +} diff --git a/src/main/java/avatartranslator/mutation/MdAttributeMutation.java b/src/main/java/avatartranslator/mutation/MdAttributeMutation.java index e00a032dda..a4ec6996ba 100644 --- a/src/main/java/avatartranslator/mutation/MdAttributeMutation.java +++ b/src/main/java/avatartranslator/mutation/MdAttributeMutation.java @@ -58,9 +58,9 @@ public class MdAttributeMutation extends AttributeMutation implements MdMutation } public void apply(AvatarSpecification _avspec) { - AvatarAttribute aa = findElement(_avspec); - if(aa == null) { - TraceManager.addDev("Attribut inexistant"); + AvatarAttribute aa = getElement(_avspec); + if (aa == null) { + TraceManager.addDev("Unknown Attribute"); return; } aa.setInitialValue(this.getInitialValue()); diff --git a/src/main/java/avatartranslator/mutation/MdMethodMutation.java b/src/main/java/avatartranslator/mutation/MdMethodMutation.java index dcdd201963..defa4edd18 100644 --- a/src/main/java/avatartranslator/mutation/MdMethodMutation.java +++ b/src/main/java/avatartranslator/mutation/MdMethodMutation.java @@ -86,28 +86,28 @@ public class MdMethodMutation extends MethodMutation implements MdMutation { public void apply(AvatarSpecification _avspec) { AvatarBlock block = getBlock(_avspec); - AvatarMethod am = findElement(_avspec); + AvatarMethod am = getElement(_avspec); - if(am == null) { - TraceManager.addDev("Methode inexistante"); + if (am == null) { + TraceManager.addDev("Unknown Method"); return; } - if(implementationChanged) { + if (implementationChanged) { am.setImplementationProvided(isImplementationProvided()); } - if(returnParametersChanged) { + if (returnParametersChanged) { am.removeReturnAttributes(); - for(String s : getReturnParameters()) { + for (String s : getReturnParameters()) { AvatarAttribute aa = new AvatarAttribute("", AvatarType.getType(s), block, null); am.addReturnParameter(aa); } } - if(parametersChanged) { + if (parametersChanged) { am.removeAttributes(); - for(String[] s : getParameters()) { + for (String[] s : getParameters()) { AvatarAttribute aa = new AvatarAttribute(s[1], AvatarType.getType(s[0]), block, null); am.addParameter(aa); } diff --git a/src/main/java/avatartranslator/mutation/MdMutation.java b/src/main/java/avatartranslator/mutation/MdMutation.java index 76819e8be7..2340240038 100644 --- a/src/main/java/avatartranslator/mutation/MdMutation.java +++ b/src/main/java/avatartranslator/mutation/MdMutation.java @@ -49,6 +49,6 @@ import avatartranslator.*; */ public interface MdMutation { - AvatarElement findElement(AvatarSpecification _avspec); + AvatarElement getElement(AvatarSpecification _avspec); } \ No newline at end of file diff --git a/src/main/java/avatartranslator/mutation/MdSignalMutation.java b/src/main/java/avatartranslator/mutation/MdSignalMutation.java index 2fabb27ae9..f324092eec 100644 --- a/src/main/java/avatartranslator/mutation/MdSignalMutation.java +++ b/src/main/java/avatartranslator/mutation/MdSignalMutation.java @@ -49,7 +49,7 @@ import myutil.TraceManager; * @author Léon FRENOT * @version 1.0 24/06/2022 */ -public class MdSignalMutation extends SignalMutation implements MdMutation{ +public class MdSignalMutation extends SignalMutation implements MdMutation { private boolean inoutChanged = false; private boolean parametersChanged = false; @@ -80,22 +80,22 @@ public class MdSignalMutation extends SignalMutation implements MdMutation{ public void apply(AvatarSpecification _avspec) { AvatarBlock block = getBlock(_avspec); - AvatarSignal as = findElement(_avspec); + AvatarSignal as = getElement(_avspec); - if(as == null) { - TraceManager.addDev("Signal Inexistant"); + if (as == null) { + TraceManager.addDev("Unknown Signal"); return; } - if(parametersChanged) { + if (parametersChanged) { as.removeAttributes(); - for(String[] s : getParameters()) { + for (String[] s : getParameters()) { AvatarAttribute aa = new AvatarAttribute(s[1], AvatarType.getType(s[0]), block, null); as.addParameter(aa); } } - if(inoutChanged) { + if (inoutChanged) { as.setInOut(getInOut()); } } diff --git a/src/main/java/avatartranslator/mutation/MdTransitionMutation.java b/src/main/java/avatartranslator/mutation/MdTransitionMutation.java new file mode 100644 index 0000000000..7fd08b8f1b --- /dev/null +++ b/src/main/java/avatartranslator/mutation/MdTransitionMutation.java @@ -0,0 +1,174 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package avatartranslator.mutation; + +import java.util.List; + +import avatartranslator.*; + +/** + * Class MdTransitionMutation + * Creation: 27/06/2022 + * + * @author Léon FRENOT + * @version 1.0 27/06/2022 + */ +public class MdTransitionMutation extends TransitionMutation implements MdMutation { + + private TransitionMutation current; + + public MdTransitionMutation(String _blockName) { + setBlockName(_blockName); + initActions(); + current = new RmTransitionMutation(_blockName); + } + + public void setCurrentFromWithName(String _name) { + current.setFromWithName(_name); + } + + public void setCurrentFromWithUUID(String _uuid) { + current.setFromWithUUID(_uuid); + } + + public void setCurrentToWithName(String _name) { + current.setToWithName(_name); + } + + public void setCurrentToWithUUID(String _uuid) { + current.setToWithUUID(_uuid); + } + + public void setCurrentName(String _name) { + current.setName(_name); + } + + public void setCurrentUUID(String _uuid) { + current.setUUID(_uuid); + } + + public void setCurrentProbablility(double _probability) { + current.setProbability(_probability); + } + + public void setCurrentGuard(String _guard) { + current.setGuard(_guard); + } + + public void setCurrentDelays(String _minDelay, String _maxDelay) { + current.setDelays(_minDelay, _maxDelay); + } + + public void setCurrentDelayExtra(String _delayExtra) { + current.setDelayExtra(_delayExtra); + } + + public void setCurrentDelayExtras(String _delayExtra1, String _delayExtra2) { + current.setDelayExtras(_delayExtra1, _delayExtra2); + } + + public void setCurrentDelayDistributionLaw(int _law) { + current.setDelayDistributionLaw(_law); + } + + public void setCurrentDelayDistributionLaw(int _law, String _delayExtra1, String _delayExtra2) { + current.setDelayDistributionLaw(_law, _delayExtra1, _delayExtra2); + } + + public void setCurrentComputes(String _minCompute, String _maxCompute) { + current.setComputes(_minCompute, _maxCompute); + } + + public void addCurrentAction(String _action) { + current.addAction(_action); + } + + public void setCurrentNoActions() { + current.setNoActions(); + } + + @Override + public AvatarTransition getElement(AvatarSpecification _avspec) { + try { + return super.getElement(_avspec); + } catch (Exception e) { + return current.getElement(_avspec); + } + } + + public void apply(AvatarSpecification _avspec) { + AvatarTransition trans = current.getElement(_avspec); + + if (this.isFromSet()) { + AvatarStateMachineElement currentFromElement = current.getFromElement(_avspec); + AvatarStateMachineElement newFromElement = this.getFromElement(_avspec); + currentFromElement.removeNext(trans); + newFromElement.addNext(trans); + } + + if (this.isToSet()) { + AvatarStateMachineElement newToElement = this.getToElement(_avspec); + trans.removeAllNexts(); + trans.addNext(newToElement); + } + + if (this.isProbabilitySet()) { + trans.setProbability(this.getProbability()); + } + if (this.isGuardSet()) { + trans.setGuard(this.getGuard()); + } + if (this.areDelaysSet()) { + trans.setDelays(this.getMinDelay(), this.getMaxDelay()); + } + if (this.isDelayDistributionLawSet()) { + trans.setDistributionLaw(this.getDelayDistributionLaw(), this.getDelayExtra1(), this.getDelayExtra2()); + } + if (this.areComputesSet()) { + trans.setComputes(this.getMinCompute(), this.getMaxCompute()); + } + if (this.areActionsSet()) { + trans.removeAllActions(); + List<String> actions = this.getActions(); + for (String action : actions) { + trans.addAction(action); + } + } + } +} diff --git a/src/main/java/avatartranslator/mutation/MethodMutation.java b/src/main/java/avatartranslator/mutation/MethodMutation.java index e7699ca389..7cc665c090 100644 --- a/src/main/java/avatartranslator/mutation/MethodMutation.java +++ b/src/main/java/avatartranslator/mutation/MethodMutation.java @@ -97,7 +97,7 @@ public abstract class MethodMutation extends BlockStructMutation { return implementationProvided; } - public AvatarMethod findElement(AvatarSpecification _avspec) { + public AvatarMethod getElement(AvatarSpecification _avspec) { AvatarBlock block = getBlock(_avspec); return block.getAvatarMethodWithName(getName()); } diff --git a/src/main/java/avatartranslator/mutation/RmAttributeMutation.java b/src/main/java/avatartranslator/mutation/RmAttributeMutation.java index 6c5fd3e1c9..b315c68073 100644 --- a/src/main/java/avatartranslator/mutation/RmAttributeMutation.java +++ b/src/main/java/avatartranslator/mutation/RmAttributeMutation.java @@ -60,9 +60,9 @@ public class RmAttributeMutation extends AttributeMutation implements RmMutation public void apply(AvatarSpecification _avspec) { AvatarBlock block = getBlock(_avspec); List<AvatarAttribute> attr = block.getAttributes(); - AvatarAttribute aa = findElement(_avspec); - if(aa == null) { - TraceManager.addDev("Attribut inexistant"); + AvatarAttribute aa = getElement(_avspec); + if (aa == null) { + TraceManager.addDev("Unknown Attribute"); return; } attr.remove(aa); diff --git a/src/main/java/avatartranslator/mutation/RmMethodMutation.java b/src/main/java/avatartranslator/mutation/RmMethodMutation.java index deea65be9c..8bdf564e54 100644 --- a/src/main/java/avatartranslator/mutation/RmMethodMutation.java +++ b/src/main/java/avatartranslator/mutation/RmMethodMutation.java @@ -61,11 +61,11 @@ public class RmMethodMutation extends MethodMutation implements RmMutation { public void apply(AvatarSpecification _avspec) { AvatarBlock block = getBlock(_avspec); List<AvatarMethod> meth = block.getMethods(); - AvatarMethod am = findElement(_avspec); - if(am == null) { - TraceManager.addDev("Methode inexistante"); + AvatarMethod am = getElement(_avspec); + if (am == null) { + TraceManager.addDev("Unknown Method"); return; } - if(!meth.remove(am)) TraceManager.addDev("Methode dans un super-bloc"); + if (!meth.remove(am)) TraceManager.addDev("Method is from a super-bloc"); } } diff --git a/src/main/java/avatartranslator/mutation/RmMutation.java b/src/main/java/avatartranslator/mutation/RmMutation.java index 16f63e1879..7c5964a555 100644 --- a/src/main/java/avatartranslator/mutation/RmMutation.java +++ b/src/main/java/avatartranslator/mutation/RmMutation.java @@ -49,6 +49,6 @@ import avatartranslator.*; */ public interface RmMutation { - AvatarElement findElement(AvatarSpecification _avspec); + AvatarElement getElement(AvatarSpecification _avspec); } \ No newline at end of file diff --git a/src/main/java/avatartranslator/mutation/RmSignalMutation.java b/src/main/java/avatartranslator/mutation/RmSignalMutation.java index 4823320901..78a0d2e19a 100644 --- a/src/main/java/avatartranslator/mutation/RmSignalMutation.java +++ b/src/main/java/avatartranslator/mutation/RmSignalMutation.java @@ -61,11 +61,11 @@ public class RmSignalMutation extends SignalMutation implements RmMutation { public void apply(AvatarSpecification _avspec) { AvatarBlock block = getBlock(_avspec); List<AvatarSignal> sign = block.getSignals(); - AvatarSignal as = findElement(_avspec); - if(as == null) { - TraceManager.addDev("Signal inexistant"); + AvatarSignal as = getElement(_avspec); + if (as == null) { + TraceManager.addDev("Unknown Signal"); return; } - if(!sign.remove(as)) TraceManager.addDev("Signal dans un super-bloc"); + if (!sign.remove(as)) TraceManager.addDev("Signal is from a super-bloc"); } } diff --git a/src/main/java/avatartranslator/mutation/RmStateMutation.java b/src/main/java/avatartranslator/mutation/RmStateMutation.java new file mode 100644 index 0000000000..925dbeff95 --- /dev/null +++ b/src/main/java/avatartranslator/mutation/RmStateMutation.java @@ -0,0 +1,63 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package avatartranslator.mutation; + +import avatartranslator.*; + +/** + * Class RmStateMutation + * Creation: 27/06/2022 + * + * @author Léon FRENOT + * @version 1.0 27/06/2022 + */ + +public class RmStateMutation extends StateMutation implements RmMutation { + + public RmStateMutation(String _name, String _blockName) { + setName(_name); + setBlockName(_blockName); + } + + public void apply(AvatarSpecification _avspec) { + AvatarState state = getElement(_avspec); + AvatarStateMachine asm = getAvatarStateMachine(_avspec); + asm.removeElement(state); + } +} diff --git a/src/main/java/avatartranslator/mutation/RmTransitionMutation.java b/src/main/java/avatartranslator/mutation/RmTransitionMutation.java new file mode 100644 index 0000000000..b566f6c1fb --- /dev/null +++ b/src/main/java/avatartranslator/mutation/RmTransitionMutation.java @@ -0,0 +1,70 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package avatartranslator.mutation; + +import avatartranslator.*; +//import myutil.TraceManager; + +/** + * Class RmTransitionMutation + * Creation: 27/06/2022 + * + * @author Léon FRENOT + * @version 1.0 27/06/2022 + */ +public class RmTransitionMutation extends TransitionMutation implements RmMutation { + + public RmTransitionMutation(String _blockName) { + setBlockName(_blockName); + initActions(); + } + + public void apply(AvatarSpecification _avspec) { + AvatarTransition trans = getElement(_avspec); + AvatarStateMachine asm = getAvatarStateMachine(_avspec); + AvatarStateMachineElement fromElement = getFromElement(_avspec); + //TraceManager.addDev(fromElement.toString()); + //TraceManager.addDev(String.valueOf(trans == null)); + + fromElement.removeNext(trans); + asm.removeElement(trans); + + } + +} diff --git a/src/main/java/avatartranslator/mutation/SignalMutation.java b/src/main/java/avatartranslator/mutation/SignalMutation.java index b7a394e898..d26b7c62b3 100644 --- a/src/main/java/avatartranslator/mutation/SignalMutation.java +++ b/src/main/java/avatartranslator/mutation/SignalMutation.java @@ -64,7 +64,7 @@ public abstract class SignalMutation extends MethodMutation { } @Override - public AvatarSignal findElement(AvatarSpecification _avspec) { + public AvatarSignal getElement(AvatarSpecification _avspec) { AvatarBlock block = getBlock(_avspec); return block.getAvatarSignalWithName(getName()); } diff --git a/src/main/java/avatartranslator/mutation/StateMutation.java b/src/main/java/avatartranslator/mutation/StateMutation.java new file mode 100644 index 0000000000..b815548483 --- /dev/null +++ b/src/main/java/avatartranslator/mutation/StateMutation.java @@ -0,0 +1,68 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package avatartranslator.mutation; + +import avatartranslator.*; + +/** + * Class StateMutation + * Creation: 27/06/2022 + * + * @author Léon FRENOT + * @version 1.0 27/06/2022 + */ + +public abstract class StateMutation extends AvatarStateMachineElementMutation { + private String name; + + public void setName(String _name) { + name = _name; + } + + public String getName() { + return name; + } + + public AvatarState getElement(AvatarSpecification _avspec) { + AvatarStateMachine asm = getAvatarStateMachine(_avspec); + AvatarState state = asm.getStateWithName(getName()); + return state; + } + +} diff --git a/src/main/java/avatartranslator/mutation/TransitionMutation.java b/src/main/java/avatartranslator/mutation/TransitionMutation.java new file mode 100644 index 0000000000..e5a77fd770 --- /dev/null +++ b/src/main/java/avatartranslator/mutation/TransitionMutation.java @@ -0,0 +1,347 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package avatartranslator.mutation; + +import avatartranslator.*; +//import myutil.TraceManager; + +import java.util.LinkedList; +import java.util.List; + +/** + * Class TransitionMutation + * Creation: 27/06/2022 + * + * @author Léon FRENOT + * @version 1.0 27/06/2022 + */ + +public abstract class TransitionMutation extends AvatarStateMachineElementMutation { + + private String fromString; + private String toString; + private String nameString; + + private int fromType = UNDEFINED_TYPE; + private int toType = UNDEFINED_TYPE; + private int nameType = UNDEFINED_TYPE; + + private double probability; + private boolean probabilitySet = false; + + private String guard = ""; + private boolean guardSet = false; + + private String minDelay = "", maxDelay = ""; + private boolean delaysSet = false; + private String delayExtra1 = ""; // Used for some of the distribution law + private String delayExtra2 = ""; // Used for some of the distribution law + private int delayDistributionLaw; + private boolean delayDistributionLawSet = false; + + private String minCompute = "", maxCompute = ""; + private boolean computesSet = false; + + private List<String> actions; // actions on variable, or method call + private boolean actionsSet = false; + + private void setFrom(String _name) { + fromString = _name; + } + + public void setFromWithName(String _name) { + setFrom(_name); + fromType = NAME_TYPE; + } + + public void setFromWithUUID(String _uuid) { + setFrom(_uuid); + fromType = UUID_TYPE; + } + + public String getFrom() { + return fromString; + } + + public AvatarStateMachineElement getFromElement(AvatarSpecification _avspec) { + if (isFromSet()) return getElement(_avspec, fromType, fromString); + AvatarTransition trans = getElement(_avspec); + AvatarStateMachine asm = getAvatarStateMachine(_avspec); + return asm.getElementsLeadingTo(trans).get(0); + } + + public boolean isFromSet() { + return fromType!=UNDEFINED_TYPE; + } + + private void setTo(String _name) { + toString = _name; + } + + public void setToWithName(String _name) { + setTo(_name); + toType = NAME_TYPE; + } + + public void setToWithUUID(String _uuid) { + setTo(_uuid); + toType = UUID_TYPE; + } + + public String getTo() { + return toString; + } + + public AvatarStateMachineElement getToElement(AvatarSpecification _avspec) { + if (isToSet()) return getElement(_avspec, toType, toString); + AvatarTransition trans = getElement(_avspec); + return trans.getNext(0); + } + + public boolean isToSet() { + return toType!=UNDEFINED_TYPE; + } + + public void setName(String _name) { + nameString = _name; + nameType = NAME_TYPE; + } + + public void setUUID(String _uuid) { + nameString = _uuid; + nameType = UUID_TYPE; + } + + public String getName() { + if (nameType == UNDEFINED_TYPE) return "undefined"; + return nameString; + } + + public void setProbability(double _probability) { + probability = _probability; + probabilitySet = true; + } + + public boolean isProbabilitySet() { + return probabilitySet; + } + + public double getProbability() { + return probability; + } + + public void setGuard(String _guard) { + guard = _guard; + guardSet = true; + } + + public boolean isGuardSet() { + return guardSet; + } + + public String getGuard() { + return guard; + } + + public AvatarGuard getAvatarGuard(AvatarSpecification _avspec) { + return AvatarGuard.createFromString(getBlock(_avspec), getGuard()); + } + + public void setDelays(String _minDelay, String _maxDelay) { + minDelay = _minDelay; + maxDelay = _maxDelay; + delaysSet = true; + } + + public boolean areDelaysSet() { + return delaysSet; + } + + public String getMinDelay() { + return minDelay; + } + + public String getMaxDelay() { + if (maxDelay.trim().length() == 0) { + return getMinDelay(); + } + return maxDelay; + } + + public void setDelayExtra(String _delayExtra) { + delayExtra1 = _delayExtra; + } + + public void setDelayExtras(String _delayExtra1, String _delayExtra2) { + setDelayExtra(_delayExtra1); + delayExtra2 = _delayExtra2; + } + + public String getDelayExtra1() { + return delayExtra1; + } + + public String getDelayExtra2() { + return delayExtra2; + } + + public void setDelayDistributionLaw(int _law) { + delayDistributionLaw = _law; + delayDistributionLawSet = true; + } + + public void setDelayDistributionLaw(int _law, String _delayExtra1, String _delayExtra2) { + setDelayDistributionLaw(_law); + setDelayExtras(_delayExtra1, _delayExtra2); + } + + public boolean isDelayDistributionLawSet() { + return delayDistributionLawSet; + } + + public int getDelayDistributionLaw() { + return delayDistributionLaw; + } + + public void setComputes(String _minCompute, String _maxCompute) { + minCompute = _minCompute; + maxCompute = _maxCompute; + computesSet = true; + } + + public boolean areComputesSet() { + return computesSet; + } + + public String getMinCompute() { + return minCompute; + } + + public String getMaxCompute() { + if (maxCompute.trim().length() == 0) { + return getMinCompute(); + } + return maxCompute; + } + + public void initActions() { + actions = new LinkedList<>(); + } + + public void addAction(String _action) { + actions.add(_action); + actionsSet = true; + } + + public void setNoActions() { + actions.clear(); + actionsSet = true; + } + + public boolean areActionsSet() { + return actionsSet; + } + + public List<String> getActions() { + return actions; + } + + public String getAction(int _index) { + return getActions().get(_index); + } + + public AvatarTransition getElement(AvatarSpecification _avspec) { + //TraceManager.addDev(String.valueOf(nameType)); + if (nameType == UNDEFINED_TYPE) { + AvatarStateMachineElement fromElement = getElement(_avspec, fromType, fromString); + //TraceManager.addDev(fromElement.toString()); + AvatarStateMachineElement toElement = getElement(_avspec, toType, toString); + //TraceManager.addDev(toElement.toString()); + List<AvatarStateMachineElement> fromNexts = fromElement.getNexts(); + for (AvatarStateMachineElement elt : fromNexts) { + //TraceManager.addDev(elt.toString()); + if (elt instanceof AvatarTransition) { + AvatarTransition trans = (AvatarTransition)elt; + boolean flag = trans.hasNext(toElement); + + if (flag && isProbabilitySet()) + flag = (trans.getProbability() == this.getProbability()); + + if (flag && isGuardSet()) + flag = (trans.getGuard().equals(this.getAvatarGuard(_avspec))); + + if (flag && areDelaysSet()) + if (trans.getMinDelay().equals(this.getMinDelay())) + flag = trans.getMaxDelay().equals(this.getMaxDelay()); + else flag = false; + + if (flag && isDelayDistributionLawSet()) { + if (trans.getDelayDistributionLaw() == this.getDelayDistributionLaw()) { + if (trans.getDelayExtra1().equals("") || trans.getDelayExtra1().equals(this.getDelayExtra1())) { + flag = (trans.getDelayExtra2().equals("") || trans.getDelayExtra2().equals(this.getDelayExtra2())); + } + else flag = false; + } + else flag = false; + } + + if (flag && areComputesSet()) + if (trans.getMinCompute().equals(this.getMinCompute())) + flag = trans.getMaxCompute().equals(this.getMaxCompute()); + else flag = false; + + if (flag && areActionsSet()) { + int len = trans.getNbOfAction(); + if ( len == this.getActions().size()) { + for (int i = 0; flag && i < len; i++) { + flag = (trans.getAction(i).toString() == AvatarTerm.createActionFromString(getBlock(_avspec), this.getAction(i)).toString()); + } + } + } + + if (flag) return (AvatarTransition)elt; + } + } + return null; + } + AvatarStateMachineElement element = getElement(_avspec, nameType, nameString); + if (element != null && element instanceof AvatarTransition) return (AvatarTransition)element; + return null; + } +} diff --git a/ttool/src/test/java/avatartranslator/AvatarMutationTests.java b/ttool/src/test/java/avatartranslator/AvatarMutationTests.java index 3f527747fb..97b99a90c6 100644 --- a/ttool/src/test/java/avatartranslator/AvatarMutationTests.java +++ b/ttool/src/test/java/avatartranslator/AvatarMutationTests.java @@ -237,6 +237,114 @@ public class AvatarMutationTests { assertTrue(block.getSignals().get(0).getListOfAttributes().size() == 1); TraceManager.addDev(block.getSignals().get(0).toString()); + } + + @Test + public void testAddState() { + assertTrue(block.getStateMachine().getNbOfStatesElement() == 0); + StateMutation mutation = new AddStateMutation("state0", "block"); + mutation.apply(as); + assertTrue(block.getStateMachine().getNbOfStatesElement() == 1); + } + + public void add2States() { + testAddState(); + StateMutation mutation0 = new AddStateMutation("state1", "block"); + mutation0.apply(as); + } + @Test + public void testRmState() { + add2States(); + assertTrue(block.getStateMachine().getNbOfStatesElement() == 2); + StateMutation mutation = new RmStateMutation("state0", "block"); + mutation.apply(as); + assertTrue(block.getStateMachine().getNbOfStatesElement() == 1); + assertTrue(block.getStateMachine().getState(0).getName().equals("state1")); + } + + @Test + public void testAddTransition() { + add2States(); + TransitionMutation mutation0 = new AddTransitionMutation("block"); + mutation0.setFromWithName("state0"); + mutation0.setToWithName("state1"); + mutation0.apply(as); + assertTrue(block.getStateMachine().getState(0).getNexts().size()==1); + TransitionMutation mutation = new AddTransitionMutation("block"); + mutation.setFromWithName("state0"); + mutation.setToWithName("state1"); + mutation.setName("trans"); + mutation.setProbability(0.5); + mutation.setGuard("x > 1"); + mutation.setDelays("0", "5"); + mutation.setDelayDistributionLaw(4, "1", "6"); + mutation.setComputes("12", "42"); + mutation.addAction("x = 1"); + mutation.apply(as); + AvatarTransition trans = mutation.getElement(as); + assertTrue(trans.getName().equals("trans")); + assertTrue(trans.getGuard() != null); + assertTrue(trans.getProbability() == 0.5); + assertTrue(trans.getNbOfAction() == 1); + assertTrue(trans.getMinDelay().equals("0")); + assertTrue(trans.getMaxDelay().equals("5")); + assertTrue(trans.getDelayDistributionLaw() == 4); + assertTrue(trans.getDelayExtra1().equals("1")); + assertTrue(trans.getDelayExtra2().equals("6")); + assertTrue(trans.getMinCompute().equals("12")); + assertTrue(trans.getMaxCompute().equals("42")); + TraceManager.addDev(trans.toString()); + } + + public void add2Trans() { + add2States(); + TransitionMutation mutation0 = new AddTransitionMutation("block"); + mutation0.setFromWithName("state0"); + mutation0.setToWithName("state1"); + mutation0.apply(as); + TransitionMutation mutation = new AddTransitionMutation("block"); + mutation.setFromWithName("state0"); + mutation.setToWithName("state1"); + mutation.setName("trans"); + mutation.setProbability(0.5); + mutation.setGuard("x > 1"); + mutation.setDelays("0", "5"); + mutation.setDelayDistributionLaw(4, "1", "6"); + mutation.setComputes("12", "42"); + mutation.addAction("x = 1"); + mutation.apply(as); + } + + @Test + public void testRmMutation() { + add2Trans(); + //TraceManager.addDev(block.getStateMachine().getState(0).toString()); + TransitionMutation mutation = new RmTransitionMutation("block"); + mutation.setName("trans"); + mutation.apply(as); + assertTrue(block.getStateMachine().getState(0).getNexts().size()==1); + mutation = new RmTransitionMutation("block"); + mutation.setFromWithName("state0"); + mutation.setToWithName("state1"); + //TraceManager.addDev(block.getStateMachine().getState(0).toString()); + mutation.apply(as); + //TraceManager.addDev(block.getStateMachine().getState(0).toString()); + assertTrue(block.getStateMachine().getState(0).getNexts().size()==0); + } + + @Test + public void testMdMutation() { + add2Trans(); + MdTransitionMutation mutation = new MdTransitionMutation("block"); + mutation.setCurrentNoActions(); + mutation.addAction("x = x + 2"); + mutation.setCurrentFromWithName("state0"); + mutation.setCurrentToWithName("state1"); + AvatarTransition trans = mutation.getElement(as); + assertTrue(trans.getNbOfAction() == 0); + mutation.apply(as); + assertTrue(trans.getNbOfAction() == 1); + TraceManager.addDev(trans.toString()); } } \ No newline at end of file -- GitLab