Skip to content
Snippets Groups Projects
Commit d0a4ff3c authored by dgelessus's avatar dgelessus
Browse files

Make compareModuleAndConfig work properly and fix affected tests

parent cc78428d
No related branches found
No related tags found
No related merge requests found
...@@ -12,8 +12,8 @@ public class DeferredSetSizeTest { ...@@ -12,8 +12,8 @@ public class DeferredSetSizeTest {
+ "END"; + "END";
String expectedModule = "---- MODULE test ----\n" String expectedModule = "---- MODULE test ----\n"
+ "CONSTANTS S\n" + "CONSTANTS S\n"
+ "======"; + "====";
String expectedConfig = "CONSTANTS S = {S1, S2, S3} "; String expectedConfig = "CONSTANTS\nS = {S1,S2,S3}\n";
compareModuleAndConfig(expectedModule, expectedConfig, machine); compareModuleAndConfig(expectedModule, expectedConfig, machine);
} }
...@@ -27,8 +27,8 @@ public class DeferredSetSizeTest { ...@@ -27,8 +27,8 @@ public class DeferredSetSizeTest {
+ "EXTENDS FiniteSets\n" + "EXTENDS FiniteSets\n"
+ "CONSTANTS S\n" + "CONSTANTS S\n"
+ "ASSUME Cardinality(S) = 4\n" + "ASSUME Cardinality(S) = 4\n"
+ "======"; + "====";
String expectedConfig = "CONSTANTS S = {S1, S2, S3, S4} "; String expectedConfig = "CONSTANTS\nS = {S1,S2,S3,S4}\n";
compareModuleAndConfig(expectedModule, expectedConfig, machine); compareModuleAndConfig(expectedModule, expectedConfig, machine);
} }
...@@ -42,8 +42,8 @@ public class DeferredSetSizeTest { ...@@ -42,8 +42,8 @@ public class DeferredSetSizeTest {
+ "EXTENDS FiniteSets\n" + "EXTENDS FiniteSets\n"
+ "CONSTANTS S\n" + "CONSTANTS S\n"
+ "ASSUME 4 = Cardinality(S)\n" + "ASSUME 4 = Cardinality(S)\n"
+ "======"; + "====";
String expectedConfig = "CONSTANTS S = {S1, S2, S3, S4} "; String expectedConfig = "CONSTANTS\nS = {S1,S2,S3,S4}\n";
compareModuleAndConfig(expectedModule, expectedConfig, machine); compareModuleAndConfig(expectedModule, expectedConfig, machine);
} }
} }
...@@ -27,9 +27,10 @@ public class MachineParameterTest { ...@@ -27,9 +27,10 @@ public class MachineParameterTest {
String expectedModule = "---- MODULE test ----\n" String expectedModule = "---- MODULE test ----\n"
+ "VARIABLES a\n" + "VARIABLES a\n"
+ "Init == a \\in {1, 2, 3}\n" + "Init == a \\in {1, 2, 3}\n"
+ "\n"
+ "Next == 1 = 2 /\\ UNCHANGED <<a>>\n" + "Next == 1 = 2 /\\ UNCHANGED <<a>>\n"
+ "======"; + "====";
String expectedConfig = "INIT Init\nNEXT Next"; String expectedConfig = "INIT Init\nNEXT Next\n";
compareModuleAndConfig(expectedModule, expectedConfig, machine); compareModuleAndConfig(expectedModule, expectedConfig, machine);
} }
...@@ -53,8 +54,8 @@ public class MachineParameterTest { ...@@ -53,8 +54,8 @@ public class MachineParameterTest {
String expectedModule = "---- MODULE test ----\n" String expectedModule = "---- MODULE test ----\n"
+ "CONSTANTS AA\n" + "CONSTANTS AA\n"
+ "======"; + "====";
String expectedConfig = "CONSTANTS AA = {AA1, AA2, AA3}"; String expectedConfig = "CONSTANTS\nAA = {AA1,AA2,AA3}\n";
compareModuleAndConfig(expectedModule, expectedConfig, machine); compareModuleAndConfig(expectedModule, expectedConfig, machine);
} }
...@@ -69,7 +70,7 @@ public class MachineParameterTest { ...@@ -69,7 +70,7 @@ public class MachineParameterTest {
+ "a == 1\n" + "a == 1\n"
+ "ASSUME Cardinality(B) = 2\n" + "ASSUME Cardinality(B) = 2\n"
+ "===="; + "====";
String expectedConfig = "CONSTANTS B = {B1, B2, B3}"; String expectedConfig = "CONSTANTS\nB = {B1,B2,B3}\n";
compareModuleAndConfig(expectedModule, expectedConfig, machine); compareModuleAndConfig(expectedModule, expectedConfig, machine);
} }
......
...@@ -12,7 +12,7 @@ public class SetsClauseTest { ...@@ -12,7 +12,7 @@ public class SetsClauseTest {
+ "END"; + "END";
String expectedModule = "---- MODULE test ----\n" String expectedModule = "---- MODULE test ----\n"
+ "CONSTANTS d\n" + "CONSTANTS d\n"
+ "======"; + "====";
String expectedConfig = "CONSTANTS\n" + String expectedConfig = "CONSTANTS\n" +
"d = {d1,d2,d3}\n"; "d = {d1,d2,d3}\n";
...@@ -27,10 +27,16 @@ public class SetsClauseTest { ...@@ -27,10 +27,16 @@ public class SetsClauseTest {
+ "PROPERTIES k : d \n" + "PROPERTIES k : d \n"
+ "END"; + "END";
String expectedModule = "---- MODULE test ----\n" String expectedModule = "---- MODULE test ----\n"
+ "CONSTANTS d2asisdfapsdjfa\n" + "CONSTANTS d\n"
+ "======"; + "VARIABLES k\n"
String expectedConfig = "CONSTANTS\n" + + "Init == k \\in d\n"
"d = {d1, d2, d3}\n"; + "\n"
+ "Next == 1 = 2 /\\ UNCHANGED <<k>>\n"
+ "====";
String expectedConfig = "INIT Init\n"
+ "NEXT Next\n"
+ "CONSTANTS\n"
+ "d = {d1,d2,d3}\n";
compareModuleAndConfig(expectedModule, expectedConfig, machine); compareModuleAndConfig(expectedModule, expectedConfig, machine);
} }
...@@ -42,9 +48,9 @@ public class SetsClauseTest { ...@@ -42,9 +48,9 @@ public class SetsClauseTest {
+ "END"; + "END";
String expectedModule = "---- MODULE test ----\n" String expectedModule = "---- MODULE test ----\n"
+ "CONSTANTS a, b, c\n" + "CONSTANTS a, b, c\n"
+ "S == {a, b, c}" + "S == {a, b, c}\n"
+ "======"; + "====";
String expectedConfig = "CONSTANTS a = a\n b = b \n c = c"; String expectedConfig = "CONSTANTS\na = a\nb = b\nc = c\n";
compareModuleAndConfig(expectedModule, expectedConfig, machine); compareModuleAndConfig(expectedModule, expectedConfig, machine);
} }
} }
...@@ -113,6 +113,7 @@ public class TestUtil { ...@@ -113,6 +113,7 @@ public class TestUtil {
String name = b2tlaTranslator.getMachineName(); String name = b2tlaTranslator.getMachineName();
translateTLA2B(name, b2tlaTranslator.getModuleString(), b2tlaTranslator.getConfigString()); translateTLA2B(name, b2tlaTranslator.getModuleString(), b2tlaTranslator.getConfigString());
// TODO Check that re-translated B machine matches original input?
} }
public static void compareEqualsConfig(String expectedModule, String expectedConfig, String machine) public static void compareEqualsConfig(String expectedModule, String expectedConfig, String machine)
...@@ -124,30 +125,14 @@ public class TestUtil { ...@@ -124,30 +125,14 @@ public class TestUtil {
// parse check // parse check
translateTLA2B(name, b2tlaTranslator.getModuleString(), b2tlaTranslator.getConfigString()); translateTLA2B(name, b2tlaTranslator.getModuleString(), b2tlaTranslator.getConfigString());
// TODO Check that re-translated B machine matches original input?
assertEquals(expectedModule, b2tlaTranslator.getModuleString()); assertEquals(expectedModule, b2tlaTranslator.getModuleString());
assertEquals(expectedConfig, b2tlaTranslator.getConfigString()); assertEquals(expectedConfig, b2tlaTranslator.getConfigString());
} }
public static void compareModuleAndConfig(String expectedModule, String expectedConfig, String machine) public static void compareModuleAndConfig(String expectedModule, String expectedConfig, String machine) throws Exception {
throws BCompoundException, TLA2BException { compareEqualsConfig(expectedModule, expectedConfig, machine);
Translator b2tlaTranslator = new Translator(machine);
b2tlaTranslator.translate();
// TODO include config file in back translation from TLA+ to B
// String name = b2tlaTranslator.getMachineName();
// StringBuilder sb1 = de.tla2b.translation.Tla2BTranslator
// .translateString(name, b2tlaTranslator.getModuleString(),
// b2tlaTranslator.getConfigString());
// StringBuilder sb2 = de.tla2b.translation.Tla2BTranslator
// .translateString(name, expectedModule, expectedConfig);
// if (!sb2.toString().equals(sb1.toString())) {
// fail("expected:\n" + expectedModule + "\nbut was:\n"
// + b2tlaTranslator.getModuleString() + "\n\nexpected:\n"
// + expectedConfig + "\nbut was:\n"
// + b2tlaTranslator.getConfigString());
// }
} }
public static void compareEquals(String expected, String machine) throws BException { public static void compareEquals(String expected, String machine) throws BException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment