Skip to content
Snippets Groups Projects
Commit 6f943374 authored by hansen's avatar hansen
Browse files

Converted some prettyprint tests into integration tests

parent 54f07e5a
Branches
Tags
No related merge requests found
Showing
with 265 additions and 424 deletions
package de.b2tla.analysis;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
......@@ -15,10 +16,12 @@ import de.be4.classicalb.core.parser.node.AEqualPredicate;
import de.be4.classicalb.core.parser.node.AGreaterPredicate;
import de.be4.classicalb.core.parser.node.AIdentifierExpression;
import de.be4.classicalb.core.parser.node.AIntegerExpression;
import de.be4.classicalb.core.parser.node.AInvariantMachineClause;
import de.be4.classicalb.core.parser.node.ALessEqualPredicate;
import de.be4.classicalb.core.parser.node.APropertiesMachineClause;
import de.be4.classicalb.core.parser.node.Node;
import de.be4.classicalb.core.parser.node.PExpression;
import de.be4.classicalb.core.parser.node.PPredicate;
/**
* In the class the order of constants is determined. Constants can depend on
......@@ -32,6 +35,8 @@ public class ConstantsEvaluator extends DepthFirstAdapter {
private MachineContext machineContext;
private ValuesOfIdentifierFinder valuesOfConstantsFinder;
private HashMap<Node, Integer> integerValueTable;
private final ArrayList<Node> propertiesList;
private final ArrayList<Node> invariantList;
private LinkedHashMap<Node, Node> valueOfIdentifier;
......@@ -39,6 +44,14 @@ public class ConstantsEvaluator extends DepthFirstAdapter {
return valueOfIdentifier.get(con);
}
public ArrayList<Node> getInvariantList(){
return this.invariantList;
}
public ArrayList<Node> getPropertiesList() {
return this.propertiesList;
}
public LinkedHashMap<Node, Node> getValueOfIdentifierMap() {
return valueOfIdentifier;
}
......@@ -51,6 +64,9 @@ public class ConstantsEvaluator extends DepthFirstAdapter {
this.dependsOnIdentifierTable = new Hashtable<Node, HashSet<Node>>();
this.integerValueTable = new HashMap<Node, Integer>();
this.machineContext = machineContext;
this.propertiesList = new ArrayList<Node>();
this.invariantList = new ArrayList<Node>();
ConstantsInTreeFinder constantInTreeFinder = new ConstantsInTreeFinder();
......@@ -171,31 +187,52 @@ public class ConstantsEvaluator extends DepthFirstAdapter {
Node constraints = machineContext.getConstraintMachineClause();
if (constraints != null) {
analysePredicate(((AConstraintsMachineClause) constraints)
.getPredicates());
analysePredicate(
((AConstraintsMachineClause) constraints)
.getPredicates(), false);
}
Node properties = machineContext.getPropertiesMachineClause();
if (properties != null) {
analysePredicate(((APropertiesMachineClause) properties)
.getPredicates());
analysePredicate(
((APropertiesMachineClause) properties).getPredicates(), true);
}
Node invariantClause = machineContext.getInvariantMachineClause();
if(invariantClause != null){
analyseInvariantPredicate(((AInvariantMachineClause) invariantClause).getPredicates());
}
}
private void analysePredicate(Node n) {
if (n instanceof AEqualPredicate) {
analyseEqualsPredicate((AEqualPredicate) n);
private void analyseInvariantPredicate(Node node){
if (node instanceof AConjunctPredicate) {
AConjunctPredicate conjunction = (AConjunctPredicate) node;
analyseInvariantPredicate(conjunction.getLeft());
analyseInvariantPredicate(conjunction.getRight());
return;
} else if (n instanceof AGreaterPredicate) {
analyseGreaterPredicate((AGreaterPredicate) n);
} else if (n instanceof ALessEqualPredicate) {
analyseLessEqualPredicate((ALessEqualPredicate) n);
} else if (n instanceof AConjunctPredicate) {
analysePredicate(((AConjunctPredicate) n).getLeft());
analysePredicate(((AConjunctPredicate) n).getRight());
}
invariantList.add(node);
}
private void analysePredicate(Node node, boolean isProperties) {
if (node instanceof AEqualPredicate) {
analyseEqualsPredicate((AEqualPredicate) node);
} else if (node instanceof AGreaterPredicate) {
analyseGreaterPredicate((AGreaterPredicate) node);
} else if (node instanceof ALessEqualPredicate) {
analyseLessEqualPredicate((ALessEqualPredicate) node);
} else if (node instanceof AConjunctPredicate) {
AConjunctPredicate conjunction = (AConjunctPredicate) node;
analysePredicate(conjunction.getLeft(), isProperties);
analysePredicate(conjunction.getRight(), isProperties);
return;
}
if (isProperties) {
propertiesList.add((PPredicate) node);
}
}
private void analyseLessEqualPredicate(ALessEqualPredicate node) {
......
......@@ -152,10 +152,6 @@ public class TypeRestrictor extends DepthFirstAdapter {
putRestrictedType(r_left, new ElementOfNode(right));
removedNodes.add(n);
}
if (list.contains(r_right) && cEF.isconstant(left)) {
putRestrictedType(r_right, new ElementOfNode(left));
removedNodes.add(n);
}
return;
}
......
......@@ -113,7 +113,7 @@ public class LTLFormulaPrinter extends DepthFirstAdapter {
tlaPrinter.moduleStringAppend(" \\in ");
Node id = this.ltlFormulaVisitor.getLTLIdentifier(node
.getExistsIdentifier().getText());
tlaPrinter.printTypeOfIdentifier((AIdentifierExpression) id);
tlaPrinter.printTypeOfIdentifier((AIdentifierExpression) id, false);
tlaPrinter.moduleStringAppend(": ");
ltlFormulaVisitor.getBAst(node).apply(tlaPrinter);
tlaPrinter.moduleStringAppend(" /\\ ");
......@@ -127,7 +127,7 @@ public class LTLFormulaPrinter extends DepthFirstAdapter {
tlaPrinter.moduleStringAppend(" \\in ");
Node id = this.ltlFormulaVisitor.getLTLIdentifier(node
.getForallIdentifier().getText());
tlaPrinter.printTypeOfIdentifier((AIdentifierExpression) id);
tlaPrinter.printTypeOfIdentifier((AIdentifierExpression) id, false);
tlaPrinter.moduleStringAppend(": ");
ltlFormulaVisitor.getBAst(node).apply(tlaPrinter);
tlaPrinter.moduleStringAppend(" /\\ ");
......
......@@ -21,6 +21,7 @@ import de.b2tla.analysis.nodes.SubsetNode;
import de.b2tla.btypes.BType;
import de.b2tla.btypes.FunctionType;
import de.b2tla.btypes.IntegerType;
import de.b2tla.btypes.PairType;
import de.b2tla.btypes.SetType;
import de.b2tla.ltl.LTLFormulaVisitor;
import de.b2tla.tla.ConfigFile;
......@@ -177,8 +178,9 @@ public class TLAPrinter extends DepthFirstAdapter {
this.configFileString.append("NEXT Next\n");
}
}
if (configFile.isInvariant()) {
this.configFileString.append("INVARIANT Invariant\n");
for (int i = 0; i < configFile.getInvariantNumber(); i++) {
this.configFileString
.append("INVARIANT Invariant" + (i + 1) + "\n");
}
if (configFile.isGoal()) {
......@@ -305,18 +307,13 @@ public class TLAPrinter extends DepthFirstAdapter {
tlaModuleString.append("\n");
}
private boolean isInvariant = true;
private void printInvariant() {
PPredicate node = this.tlaModule.getInvariant();
if (node == null)
return;
isInvariant = true;
tlaModuleString.append("Invariant == ");
node.apply(this);
ArrayList<Node> invariants = this.tlaModule.getInvariantList();
for (int i = 0; i < invariants.size(); i++) {
tlaModuleString.append("Invariant" + (i + 1) + " == ");
invariants.get(i).apply(this);
tlaModuleString.append("\n");
isInvariant = false;
}
}
private void printAssertions() {
......@@ -388,7 +385,7 @@ public class TLAPrinter extends DepthFirstAdapter {
PExpression e = newList.get(i);
e.apply(this);
tlaModuleString.append(" \\in ");
printTypeOfIdentifier(e);
printTypeOfIdentifier(e, false);
if (i < newList.size() - 1) {
tlaModuleString.append(", ");
}
......@@ -770,7 +767,7 @@ public class TLAPrinter extends DepthFirstAdapter {
PExpression e = copy.get(i);
e.apply(this);
tlaModuleString.append(" \\in ");
printTypeOfIdentifier(e);
printTypeOfIdentifier(e, false);
if (i < copy.size() - 1) {
tlaModuleString.append(", ");
}
......@@ -796,7 +793,7 @@ public class TLAPrinter extends DepthFirstAdapter {
PExpression e = copy.get(i);
e.apply(this);
tlaModuleString.append(" \\in ");
printTypeOfIdentifier(e);
printTypeOfIdentifier(e, false);
if (i < copy.size() - 1) {
tlaModuleString.append(", ");
}
......@@ -942,9 +939,6 @@ public class TLAPrinter extends DepthFirstAdapter {
inAConjunctPredicate(node);
node.getLeft().apply(this);
tlaModuleString.append(" /\\ ");
if (isInvariant) {
tlaModuleString.append("\n");
}
node.getRight().apply(this);
outAConjunctPredicate(node);
break;
......@@ -1011,7 +1005,7 @@ public class TLAPrinter extends DepthFirstAdapter {
PExpression e = copy.get(i);
e.apply(this);
tlaModuleString.append(" \\in ");
printTypeOfIdentifier(e);
printTypeOfIdentifier(e, false);
if (i < copy.size() - 1) {
tlaModuleString.append(", ");
}
......@@ -1035,7 +1029,7 @@ public class TLAPrinter extends DepthFirstAdapter {
PExpression e = copy.get(i);
e.apply(this);
tlaModuleString.append(" \\in ");
printTypeOfIdentifier(e);
printTypeOfIdentifier(e, false);
if (i < copy.size() - 1) {
tlaModuleString.append(", ");
}
......@@ -1408,7 +1402,7 @@ public class TLAPrinter extends DepthFirstAdapter {
tlaModuleString.append(">>");
}
public void printTypeOfIdentifier(PExpression e) {
public void printTypeOfIdentifier(PExpression e, boolean childOfCart) {
// NodeType n = typeRestrictor.getRestrictedTypes().get(e);
ArrayList<NodeType> list = typeRestrictor.getRestrictedTypesSet(e);
if (list != null) {
......@@ -1419,9 +1413,17 @@ public class TLAPrinter extends DepthFirstAdapter {
if (i != 0)
tlaModuleString.append(")");
}
} else {
BType t = typechecker.getType(e);
if(t instanceof PairType && childOfCart){
tlaModuleString.append("(");
tlaModuleString.append(t.getTlaType());
tlaModuleString.append(")");
}else{
tlaModuleString.append(typechecker.getType(e).getTlaType());
}
}
}
private void printNodeType(NodeType n) {
......@@ -1444,7 +1446,7 @@ public class TLAPrinter extends DepthFirstAdapter {
}
for (int i = 0; i < copy.size(); i++) {
tlaModuleString.append("(");
printTypeOfIdentifier(copy.get(i));
printTypeOfIdentifier(copy.get(i), false);
tlaModuleString.append(")");
if (i < copy.size() - 1)
tlaModuleString.append(" \\times ");
......@@ -1759,7 +1761,7 @@ public class TLAPrinter extends DepthFirstAdapter {
printIdentifierList(copy);
tlaModuleString.append(" \\in ");
for (int i = 0; i < copy.size(); i++) {
printTypeOfIdentifier(copy.get(i));
printTypeOfIdentifier(copy.get(i), true);
if (i < copy.size() - 1)
tlaModuleString.append(" \\times ");
}
......
......@@ -8,7 +8,7 @@ import de.b2tla.tla.config.ConfigFileAssignment;
public class ConfigFile {
private final ArrayList<ConfigFileAssignment> assignments;
private boolean invariant;
private int invariantNumber;
private boolean spec;
private boolean init;
private boolean next;
......@@ -18,7 +18,7 @@ public class ConfigFile {
public ConfigFile(){
this.assignments = new ArrayList<ConfigFileAssignment>();
this.invariant = false;
this.invariantNumber = 0;
}
......@@ -31,8 +31,8 @@ public class ConfigFile {
}
public boolean isInvariant() {
return invariant;
public void setInvariantNumber(int number) {
this.invariantNumber = number;
}
......@@ -50,8 +50,8 @@ public class ConfigFile {
}
public void setInvariant() {
this.invariant = true;
public int getInvariantNumber() {
return this.invariantNumber;
}
......
......@@ -61,6 +61,7 @@ public class Generator extends DepthFirstAdapter {
evalMachineSets();
evalConstants();
evalDefinitions();
evalInvariant();
evalOperations();
evalGoal();
machineContext.getTree().apply(this);
......@@ -68,6 +69,14 @@ public class Generator extends DepthFirstAdapter {
evalSpec();
}
private void evalInvariant() {
AInvariantMachineClause invariantClause = machineContext.getInvariantMachineClause();
if(invariantClause!= null){
this.tlaModule.invariants.addAll(constantsEvaluator.getInvariantList());
this.configFile.setInvariantNumber(tlaModule.invariants.size());
}
}
private void evalSpec() {
if (this.configFile.isInit() && this.configFile.isNext()
&& machineContext.getLTLFormulas().size() > 0) {
......@@ -193,6 +202,10 @@ public class Generator extends DepthFirstAdapter {
}
}
private void evalOperations() {
AOperationsMachineClause node = machineContext
.getOperationMachineClause();
......@@ -225,20 +238,20 @@ public class Generator extends DepthFirstAdapter {
this.tlaModule.addToAllDefinitions(exprDef);
}
ArrayList<Node> vars = new ArrayList<Node>();
vars.addAll(machineContext.getConstants().values());
vars.removeAll(conValueTable.keySet());
ArrayList<Node> remainingConstants = new ArrayList<Node>();
remainingConstants.addAll(machineContext.getConstants().values());
remainingConstants.removeAll(conValueTable.keySet());
Node propertiesPerdicate = machineContext.getPropertiesMachineClause()
.getPredicates();
if (vars.size() != 0) {
if (remainingConstants.size() != 0) {
boolean init = false;
for (int i = 0; i < vars.size(); i++) {
Node con = vars.get(i);
for (int i = 0; i < remainingConstants.size(); i++) {
Node con = remainingConstants.get(i);
Integer value = constantsEvaluator.getIntValue(con);
if (value == null) {
init = true;
this.tlaModule.variables.add(vars.get(i));
this.tlaModule.variables.add(remainingConstants.get(i));
} else {
tlaModule.definitions.add(new TLADefinition(con, value));
}
......@@ -250,14 +263,15 @@ public class Generator extends DepthFirstAdapter {
}
} else {
tlaModule.addAssume(propertiesPerdicate);
tlaModule.assumes.addAll(constantsEvaluator.getPropertiesList());
//tlaModule.addAssume(propertiesPerdicate);
}
}
@Override
public void caseAPropertiesMachineClause(APropertiesMachineClause node) {
if (!tlaModule.isInitPredicate(node.getPredicates())) {
this.tlaModule.addAssume(node.getPredicates());
//this.tlaModule.addAssume(node.getPredicates());
}
}
......@@ -270,14 +284,7 @@ public class Generator extends DepthFirstAdapter {
}
}
@Override
public void caseAInvariantMachineClause(AInvariantMachineClause node) {
this.tlaModule.invariant = node.getPredicates();
if (B2TLAGlobals.isInvariant()) {
this.configFile.setInvariant();
}
}
@Override
public void caseAAssertionsMachineClause(AAssertionsMachineClause node) {
......
......@@ -15,9 +15,9 @@ public class TLAModule {
protected final ArrayList<TLADefinition> definitions;
protected final ArrayList<Node> constants;
private final ArrayList<Node> assumes;
protected final ArrayList<Node> assumes;
protected final ArrayList<Node> variables;
protected PPredicate invariant;
protected final ArrayList<Node> invariants;
private final ArrayList<Node> initPredicates;
protected final ArrayList<POperation> operations;
private ArrayList<PDefinition> bDefinitions;
......@@ -34,6 +34,7 @@ public class TLAModule {
this.operations = new ArrayList<POperation>();
this.bDefinitions = new ArrayList<PDefinition>();
this.assertions = new ArrayList<Node>();
this.invariants = new ArrayList<Node>();
this.allDefinitions = new ArrayList<PDefinition>();
}
......@@ -101,8 +102,8 @@ public class TLAModule {
return operations;
}
public PPredicate getInvariant() {
return invariant;
public ArrayList<Node> getInvariantList() {
return invariants;
}
public void setBDefinitions(ArrayList<PDefinition> defs){
......
......@@ -155,7 +155,7 @@ public class TLCOutput {
return TLCResult.Deadlock;
} else if (res[1].equals("Invariant")) {
String invName = res[2];
if (invName.equals("Invariant")) {
if (invName.startsWith("Invariant")) {
return TLCResult.InvariantViolation;
} else if (invName.equals("NotGoal")) {
return TLCResult.Goal;
......
......@@ -14,6 +14,7 @@ TotalBijFunc(S, S2) == {f \in [S -> S2]: S2 = Range(f) /\
Cardinality(DOMAIN f) = Cardinality(Range(f))}
ParFunc(S, S2) == UNION{[x -> S2] :x \in SUBSET S}
isEleOfParFunc(f, S, S2) == DOMAIN f \subseteq S /\ Range(f) \subseteq S2
ParInjFunc(S, S2)== {f \in ParFunc(S, S2):
Cardinality(DOMAIN f) = Cardinality(Range(f))}
......
......@@ -43,7 +43,7 @@ RECURSIVE RelIterate(_,_)
RelIterate(r, n) == CASE n < 0 -> Assert(FALSE, "ERROR")
[] n = 0 -> RelId(RelDomain(r) \cup RelRange(r))
[] n = 1 -> r
[] OTHER -> RelIterate(RelComposition(r,r), n-1)
[] OTHER -> RelComposition(r,RelIterate(r, n-1))
RECURSIVE RelClosure1(_)
RelClosure1(R) == IF RelComposition(R,R) \ R # {}
......
......@@ -3,6 +3,7 @@ package de.b2tla.analysis;
import static de.b2tla.util.TestUtil.compare;
import org.junit.Ignore;
import org.junit.Test;
public class ConstantsTest {
......@@ -62,7 +63,7 @@ public class ConstantsTest {
compare(expected, machine);
}
@Ignore
@Test
public void testConstantGreaterThan() throws Exception {
String machine = "MACHINE test\n"
......@@ -76,6 +77,7 @@ public class ConstantsTest {
compare(expected, machine);
}
@Ignore
@Test
public void testConstantGreaterThan2() throws Exception {
String machine = "MACHINE test\n"
......
package de.b2tla.analysis;
import static de.b2tla.util.TestUtil.compare;
import static de.b2tla.util.TestUtil.compareEquals;
import org.junit.Test;
import de.b2tla.exceptions.SubstitutionException;
public class UnchangedVariablesTest {
@Test
public void testIfThen() throws Exception {
String machine = "MACHINE test\n"
+ "VARIABLES a,b,c\n"
+ "INVARIANT a = 1 & b = 1 & c = 1\n"
+ "INITIALISATION a,b,c := 1,1,1 \n"
+ "OPERATIONS foo = IF 1 = 1 THEN a := 2 END \n"
+ "END";
String expected = "---- MODULE test ----\n"
+ "VARIABLES a, b,c \n"
+ "Inv == a = 1 /\\ b = 1 /\\ c = 1\n"
+ "Init == a = 1 /\\ b = 1 /\\ c = 1\n"
+ "foo == (IF 1 = 1 THEN a' = 2 ELSE UNCHANGED <<a>>) /\\ UNCHANGED <<b,c>>\n"
+ "Next == foo\n" + "====";
compare(expected, machine);
}
@Test (expected = SubstitutionException.class)
public void testParallelSubstitution() throws Exception {
String machine = "MACHINE test\n"
+ "VARIABLES a,b,c\n"
+ "INVARIANT a = 1 & b = 1 & c = 1\n"
+ "INITIALISATION a,b,c := 1,1,1 \n"
+ "OPERATIONS foo = a := 2 || a := 3 \n"
+ "END";
compare(null, machine);
}
@Test
public void testFunctionAssignment() throws Exception {
String machine = "MACHINE test\n"
+ "VARIABLES x\n"
+ "INVARIANT x = %p.(p: {1}| 1)\n"
+ "INITIALISATION x := %p.(p: {1}| 1) \n"
+ "OPERATIONS foo = x(1):= 2 \n"
+ "END";
String expected = "---- MODULE test ----\n"
+ "VARIABLES x \n"
+ "Invariant == x = [p \\in {1} |-> 1] \n"
+ "Init == x = [p \\in {1} |-> 1] \n"
+ "foo == x' = [x EXCEPT ![1] = 2] \n"
+ "Next == foo\n" + "====";
compare(expected, machine);
}
@Test
public void testRelationAssignment() throws Exception {
String machine = "MACHINE test\n"
+ "VARIABLES x\n"
+ "INVARIANT x = {(1,2)}\n"
+ "INITIALISATION x := {(1,2)}\n"
+ "OPERATIONS foo = x(1):= 2 \n"
+ "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS Relations\n"
+ "VARIABLES x\n"
+ "Invariant == x = {<<1, 2>>}\n"
+ "Init == x = {<<1, 2>>}\n"
+ "foo == x' = RelOverride(x, {<<1, 2>>})\n\n"
+ "Next == \\/ foo\n" + "====";
compareEquals(expected, machine);
}
@Test
public void testIfThenElse() throws Exception {
String machine = "MACHINE test\n" + "VARIABLES x,y\n"
+ "INVARIANT x = 1 & y = 1\n" + "INITIALISATION x,y := 1,1 \n"
+ "OPERATIONS foo = IF x = 1 THEN x:= 2 ELSE y := 2 END \n"
+ "END";
String expected = "---- MODULE test ----\n"
+ "VARIABLES x, y \n"
+ "Inv == x = 1 /\\ y = 1\n"
+ "Init == x = 1 /\\ y = 1\n"
+ "foo == IF x = 1 THEN x' = 2 /\\ UNCHANGED <<y>> ELSE y' = 2 /\\ UNCHANGED <<x>>\n"
+ "Next == foo\n" + "====";
compare(expected, machine);
}
@Test
public void testChoice() throws Exception {
String machine = "MACHINE test\n" + "VARIABLES x,y\n"
+ "INVARIANT x = 1 & y = 1\n"
+ "INITIALISATION x,y := 1,1 \n"
+ "OPERATIONS foo = CHOICE x := 1 OR y:= 2 END\n"
+ "END";
String expected = "---- MODULE test ----\n"
+ "VARIABLES x, y \n"
+ "Inv == x = 1 /\\ y = 1\n"
+ "Init == x = 1 /\\ y = 1\n"
+ "foo == (x' = 1 /\\ UNCHANGED <<y>>) \\/ (y' = 2 /\\ UNCHANGED <<x>>)\n"
+ "Next == foo\n" + "====";
compare(expected, machine);
}
}
package de.b2tla.prettyprint;
import static de.b2tla.util.TestUtil.*;
import static org.junit.Assert.assertEquals;
import org.junit.Ignore;
import org.junit.Test;
public class BBuildInsTest {
/*
* Set BuiltIns
*/
@Ignore
@Test
public void testStrictSubset() throws Exception {
String machine = "MACHINE test\n" + "PROPERTIES {1} <<: {1,2} \n"
+ "END";
String expected = "---- MODULE test ----\n"
+ "ASSUME {1} \\in (SUBSET({1, 2}) \\ {{1, 2}})\n" + "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testNotSubset() throws Exception {
String machine = "MACHINE test\n" + "PROPERTIES {1} /<: {2} \n" + "END";
String expected = "---- MODULE test ----\n" + "EXTENDS BBuiltIns\n"
+ "ASSUME notSubset({1}, {2})\n" + "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testPowerSet1() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES POW1({1,2}) = {{1}, {2}, {1, 2}} \n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS BBuiltIns\n"
+ "ASSUME POW1({1, 2}) = {{1}, {2}, {1, 2}}\n"
+ "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testFin() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES FIN({1,2}) = {{}, {1}, {2}, {1, 2}} \n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS BBuiltIns\n"
+ "ASSUME FIN({1, 2}) = {{}, {1}, {2}, {1, 2}}\n"
+ "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testFin1() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES FIN1({1,2}) = {{1}, {2}, {1, 2}} \n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS BBuiltIns\n"
+ "ASSUME FIN1({1, 2}) = {{1}, {2}, {1, 2}}\n"
+ "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testNotStrictSubset() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES {1} /<<: {1} \n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS BBuiltIns\n"
+ "ASSUME notStrictSubset({1}, {1})\n"
+ "====";
assertEquals(expected, translate(machine));
}
@Ignore
@Test
public void testQuantifiedIntersection() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES INTER(z).(z: {1,2} & 1 = 1| {z}) = {} \n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS BBuiltIns\n"
+ "ASSUME Inter({{z}: z \\in {z \\in {1, 2}: 1 = 1}}) = {}\n"
+ "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testSigma() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES SIGMA(z).(z : {1,2,3}| z+z) = 12 \n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS Naturals, BBuiltIns\n"
+ "ASSUME Sigma({z + z : z \\in {1, 2, 3}}) = 12\n"
+ "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testSigma2() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES SIGMA(z).(z : {1,2,3} & 1=1| z+z) = 12\n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS Naturals, BBuiltIns\n"
+ "ASSUME Sigma({z + z : z \\in {z \\in {1, 2, 3} : 1 = 1}}) = 12\n"
+ "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testPi() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES PI(z).(z : {1,2,3}| z+z) = 12 \n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS Naturals, BBuiltIns\n"
+ "ASSUME Pi({z + z : z \\in {1, 2, 3}}) = 12\n"
+ "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testPi2() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES PI(z).(z : {1,2,3} & 1=1| z+z) = 12\n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS Naturals, BBuiltIns\n"
+ "ASSUME Pi({z + z : z \\in {z \\in {1, 2, 3} : 1 = 1}}) = 12\n"
+ "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testSucc() throws Exception {
String machine = "MACHINE test\n" + "PROPERTIES succ(3) = 4 \n" + "END";
String expected = "---- MODULE test ----\n" + "EXTENDS BBuiltIns\n"
+ "ASSUME succ[3] = 4\n" + "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testPred() throws Exception {
String machine = "MACHINE test\n" + "PROPERTIES pred(2) = 1 \n" + "END";
String expected = "---- MODULE test ----\n" + "EXTENDS BBuiltIns\n"
+ "ASSUME pred[2] = 1\n" + "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testMin() throws Exception {
String machine = "MACHINE test\n" + "PROPERTIES min({1}) = 1 \n" + "END";
String expected = "---- MODULE test ----\n" + "EXTENDS BBuiltIns\n"
+ "ASSUME Min({1}) = 1\n" + "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testMax() throws Exception {
String machine = "MACHINE test\n" + "PROPERTIES max({1}) = 1 \n" + "END";
String expected = "---- MODULE test ----\n" + "EXTENDS BBuiltIns\n"
+ "ASSUME Max({1}) = 1\n" + "====";
compareEquals(expected, machine);
}
@Ignore
@Test
public void testMaxInt() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES MAXINT = MAXINT \n" + "END";
String expected = "---- MODULE test ----\n"
+ "ASSUME 4 = 4\n" + "====";
compare(expected, machine);
}
@Ignore
@Test
public void testMinInt() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES MININT = MININT \n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS Integers\n"
+ "ASSUME -1 = -1\n" + "====";
compare(expected, machine);
}
}
package de.b2tla.prettyprint;
import static de.b2tla.util.TestUtil.compareEquals;
import org.junit.Test;
public class DifferentTranslationsTest {
@Test
public void testTotalFunctionElementOf() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES {(1,1)} : {1} --> {1}\n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS FunctionsAsRelations\n"
+ "ASSUME {<<1, 1>>} \\in RelTotalFuncEleOf({1}, {1})\n"
+ "====";
compareEquals(expected, machine);
}
@Test
public void testTotalFunction() throws Exception {
String machine = "MACHINE test\n"
+ "PROPERTIES {{(1,1)}} = {1} --> {1}\n" + "END";
String expected = "---- MODULE test ----\n"
+ "EXTENDS FunctionsAsRelations\n"
+ "ASSUME {{<<1, 1>>}} = RelTotalFunc({1}, {1})\n"
+ "====";
compareEquals(expected, machine);
}
}
......@@ -4,6 +4,8 @@ import static de.b2tla.util.TestUtil.compare;
import org.junit.Test;
import de.b2tla.exceptions.SubstitutionException;
public class OperationsTest {
@Test
......@@ -44,6 +46,17 @@ public class OperationsTest {
}
@Test (expected = SubstitutionException.class)
public void testParallelSubstitution() throws Exception {
String machine = "MACHINE test\n"
+ "VARIABLES a,b,c\n"
+ "INVARIANT a = 1 & b = 1 & c = 1\n"
+ "INITIALISATION a,b,c := 1,1,1 \n"
+ "OPERATIONS foo = a := 2 || a := 3 \n"
+ "END";
compare(null, machine);
}
@Test
public void testBlockSubstitution() throws Exception {
String machine = "MACHINE test\n"
......
......@@ -35,7 +35,7 @@ public class BasicsTest extends AbstractParseMachineTest{
@Test
public void testRunTLC() throws Exception {
String[] a = new String[] { machine.getPath() };
//B2TLAGlobals.setDeleteOnExit(true);
B2TLAGlobals.setDeleteOnExit(true);
assertEquals(error, B2TLA.test(a));
}
......
package de.b2tla.tlc.integration;
import static de.b2tla.tlc.TLCOutput.TLCResult.NoError;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import de.b2tla.B2TLA;
import de.b2tla.B2TLAGlobals;
public class SingleConfigurations {
@Test
public void TautologiesPl() throws Exception {
B2TLAGlobals.setDeleteOnExit(true);
String[] a = new String[] { "../probprivate/public_examples/TLC/others/TautologiesPL.mch", "-nodead"};
assertEquals(NoError, B2TLA.test(a));
}
}
MACHINE Minus
PROPERTIES
/* arithmetic subtraction */
4 - 1 = 5 - 2
& 8 - 4 - 3 = 1
/* set subtraction */
& {1,2,3} - {2,3} = {1}
& {{1}, {2}} - {{2}} = {{1}}
& {1,2,3} - {2,3} - {1} = {}
END
MACHINE test
VARIABLES a,b,c, func, rela
INVARIANT a = 1 & b = 1 & c = 1 & func = %p.(p: {1}| 1) & rela = {(1,1)}
INITIALISATION a,b,c := 1,1,1 || func := %p.(p: {1}| 1) || rela := {(1,1)}
OPERATIONS
IfElseOp1 = IF 1 = 1 THEN a := 1 END;
IfElseOp2 = IF 1 = 2 THEN a := 1 END;
IfThenElse = IF a = 1 THEN b:= 1 ELSE c := 1 END;
Choice = CHOICE a := 1 OR b:= 1 END;
FuncOp = func(1):= 1;
RelOp = rela(1):= 1
END
\ No newline at end of file
MACHINE BBuiltInsTest
PROPERTIES
/* strict subset */
{1} <<: {1,2}
& {} <<: {1}
& not({} <<: {})
& not({1} <<: {1})
/* not subset */
& {1} /<: {2}
& {1,2} /<: {2}
& not({1} /<: {1,2})
& not({1} /<: {1})
/* not strict subset */
& {1} /<<: {2}
& {1} /<<: {1}
& {} /<<: {}
& not({1} /<<: {1,2})
& not({} /<<: {1})
/* POW1 */
& POW1({}) = {}
& POW1({1}) = {{1}}
& POW1({1,2}) = {{1}, {2}, {1,2}}
/* FIN */
& FIN({}) = {{}}
& FIN({1}) = {{}, {1}}
& FIN({1,2}) = {{}, {1}, {2}, {1,2}}
/* FIN1 */
& FIN1({}) = {}
& FIN1({1}) = {{1}}
& FIN1({1,2}) = {{1}, {2}, {1,2}}
/* Quantified intersection */
& INTER(z).(z: {1,2}| {z}) = {}
& INTER(x1).(x1: {2,4}| {y1 | y1 : 0..10 & y1 <= x1}) = {0,1,2}
/* Quantified union */
& UNION(z).(z: {1,2}| {z}) = {1,2}
& UNION(x1).(x1: {2,4}| {y1 | y1 : 0..10 & y1 <= x1}) = {0,1,2,3,4}
/* Sigma */
& SIGMA(z).(z : {1,2,3}| z+z) = 12
& SIGMA(z).(z : {1,2,3} & 1=1| z+z) = 12
& SIGMA(x).(x : {1,2,3}| x+1) = 9
/* Pi */
& PI(z).(z : {1,2,3}| z+z) = 12
& PI(z).(z : {1,2,3} & 1=1| z+z) = 12
& PI(x).(x : {1,2,3}| x) = 6
/* Successor */
& succ(3) = 4
& succ(0) = 1
& succ(-1) = 0
/* Predecessor */
& pred(3) = 2
& pred(1) = 0
& pred(0) = -1
/* Minimum */
& min({1}) = 1
& min({1,2}) = 1
/* Maximum */
& max({1}) = 1
& max({1,2}) = 2
/* MaxInt */
& MAXINT = 4
/* MinInt */
& MININT = -1
END
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment