Beispiel #1
0
 @Test
 public void testInstance() throws Exception {
   String path = "src/test/resources/prettyprint/instance/let/";
   StringBuilder sb = TestUtil.translate(path + "InstanceLet.tla");
   String expected = TestUtil.fileToString(path + "InstanceLet.mch");
   assertEquals(TestUtil.getTreeAsString(expected), TestUtil.getTreeAsString(sb.toString()));
 }
Beispiel #2
0
  @Test
  public void testNotIn() throws Exception {
    ToolIO.reset();
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "ASSUME 1 \\notin {} \n"
            + "=================================";

    StringBuilder sb = TestUtil.translateString(module);
    final String expected = "MACHINE Testing\n" + "PROPERTIES 1 /: {} \n" + "END";
    assertEquals(TestUtil.getTreeAsString(expected), TestUtil.getTreeAsString(sb.toString()));
  }
Beispiel #3
0
  /**
   * ******************************************************************** UNION
   * ********************************************************************
   */
  @Test
  public void testUnion() throws Exception {
    ToolIO.reset();
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "ASSUME UNION {{1},{2}} = {1,2} \n"
            + "=================================";

    StringBuilder sb = TestUtil.translateString(module);
    final String expected = "MACHINE Testing\n" + "PROPERTIES union({{1},{2}}) = {1,2} \n" + "END";
    assertEquals(TestUtil.getTreeAsString(expected), TestUtil.getTreeAsString(sb.toString()));
  }
Beispiel #4
0
  /**
   * ******************************************************************** SUBSET: conforms POW in B
   * ********************************************************************
   */
  @Test
  public void testSubset() throws Exception {
    ToolIO.reset();
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "ASSUME {{},{1}} = SUBSET {1,2} \n"
            + "=================================";

    StringBuilder sb = TestUtil.translateString(module);
    final String expected = "MACHINE Testing\n" + "PROPERTIES {{},{1}} = POW({1,2}) \n" + "END";
    assertEquals(TestUtil.getTreeAsString(expected), TestUtil.getTreeAsString(sb.toString()));
  }
Beispiel #5
0
  @Test
  public void testSetOfAll() throws Exception {
    ToolIO.reset();
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "EXTENDS Naturals \n"
            + "ASSUME {1} = {x + y+ 2:  x \\in {1,2}, y \\in {1} } \n"
            + "=================================";

    StringBuilder sb = TestUtil.translateString(module);
    final String expected =
        "MACHINE Testing\n"
            + "PROPERTIES {1} = {t_|#x, y.(x : {1, 2} & y : {1} & t_ = x + y + 2)} \n"
            + "END";
    assertEquals(TestUtil.getTreeAsString(expected), TestUtil.getTreeAsString(sb.toString()));
  }
Beispiel #6
0
  @Test
  public void testSetEnumeration2() throws Exception {
    ToolIO.reset();
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "CONSTANTS k\n"
            + "ASSUME k = {TRUE, 1 = 1}\n"
            + "=================================";

    StringBuilder sb = TestUtil.translateString(module);
    final String expected =
        "MACHINE Testing\n"
            + "ABSTRACT_CONSTANTS k\n"
            + "PROPERTIES k : POW(BOOL) & k = {TRUE, bool(1=1)} \n"
            + "END";
    assertEquals(TestUtil.getTreeAsString(expected), TestUtil.getTreeAsString(sb.toString()));
  }
Beispiel #7
0
 @Test(expected = TypeErrorException.class)
 public void testCartesianProductException() throws FrontEndException, TLA2BException {
   final String module =
       "-------------- MODULE Testing ----------------\n"
           + "CONSTANTS k \n"
           + "ASSUME k = BOOLEAN \\X 1 \n"
           + "=================================";
   TestUtil.typeCheckString(module);
 }
Beispiel #8
0
  /**
   * ******************************************************************** Set Enumeration: {1,2,3}
   * ********************************************************************
   */
  @Test
  public void testSetEnumeration() throws Exception {
    ToolIO.reset();
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "CONSTANTS k\n"
            + "ASSUME k = {1,2,3}\n"
            + "=================================";

    StringBuilder sb = TestUtil.translateString(module);
    System.out.println(sb);
    final String expected =
        "MACHINE Testing\n"
            + "ABSTRACT_CONSTANTS k\n"
            + "PROPERTIES k : POW(INTEGER) & k = {1,2,3} \n"
            + "END";
    assertEquals(TestUtil.getTreeAsString(expected), TestUtil.getTreeAsString(sb.toString()));
  }
Beispiel #9
0
  @Test(expected = TypeErrorException.class)
  public void testTuple2Elements() throws FrontEndException, TLA2BException {
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "CONSTANTS k, k2, k3 \n"
            + "ASSUME k = <<k2, k3>> /\\ k3 = TRUE \n"
            + "=================================";

    TestUtil.typeCheckString(module);
  }
Beispiel #10
0
  @Test(expected = TypeErrorException.class)
  public void testTypeConflict6() throws FrontEndException, TLA2BException {
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "CONSTANTS a,b \n"
            + "ASSUME a = [x|->1] /\\ b = [y|->a, x|->1] /\\ a=b  \n"
            + "=================================";

    TestUtil.typeCheckString(module);
  }
Beispiel #11
0
 /**
  * ******************************************************************** Cartesian Product
  * ********************************************************************
  */
 @Test
 public void testCartesianProduct2() throws FrontEndException, TLA2BException {
   final String module =
       "-------------- MODULE Testing ----------------\n"
           + "CONSTANTS k \n"
           + "ASSUME k = BOOLEAN \\X {1} \n"
           + "=================================";
   TestTypeChecker t = TestUtil.typeCheckString(module);
   assertEquals("POW(BOOL*INTEGER)", t.getConstantType("k").toString());
 }
Beispiel #12
0
  @Test(expected = TypeErrorException.class)
  public void testTypeConflict4() throws FrontEndException, TLA2BException {
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "CONSTANTS k \n"
            + "ASSUME k = [a |-> k]  \n"
            + "=================================";

    TestUtil.typeCheckString(module);
  }
Beispiel #13
0
  @Test(expected = TypeErrorException.class)
  public void testUnifyTuple4() throws FrontEndException, TLA2BException {
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "CONSTANTS k \n"
            + "ASSUME k \\in <<TRUE>>\n"
            + "=================================";

    TestUtil.typeCheckString(module);
  }
Beispiel #14
0
  @Test
  public void testTupleSingleElement() throws FrontEndException, TLA2BException {
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "CONSTANTS k \n"
            + "ASSUME k = <<TRUE>> \n"
            + "=================================";

    TestTypeChecker t = TestUtil.typeCheckString(module);
    assertEquals("POW(INTEGER*BOOL)", t.getConstantType("k").toString());
  }
Beispiel #15
0
  @Test
  public void testSimpleTuple() throws FrontEndException, TLA2BException {
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "EXTENDS Naturals \n"
            + "CONSTANTS k \n"
            + "ASSUME k = <<1,TRUE>> \n"
            + "=================================";

    TestTypeChecker t = TestUtil.typeCheckString(module);
    assertEquals("INTEGER*BOOL", t.getConstantType("k").toString());
  }
Beispiel #16
0
  @Test
  public void testTupleComponentsOfTheSameType() throws FrontEndException, TLA2BException {
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "EXTENDS Naturals \n"
            + "CONSTANTS k \n"
            + "ASSUME k = <<1,1>> \n"
            + "=================================";

    TestTypeChecker t = TestUtil.typeCheckString(module);
    assertEquals("POW(INTEGER*INTEGER)", t.getConstantType("k").toString());
  }
Beispiel #17
0
  @Test
  public void testTupleFunctionCall2() throws FrontEndException, TLA2BException {
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "EXTENDS Naturals \n"
            + "CONSTANTS k \n"
            + "ASSUME k = <<1,TRUE,\"str\">>[3] \n"
            + "=================================";

    TestTypeChecker t = TestUtil.typeCheckString(module);
    assertEquals("STRING", t.getConstantType("k").toString());
  }
Beispiel #18
0
  @Test
  public void testUnifyTuple3() throws FrontEndException, TLA2BException {
    final String module =
        "-------------- MODULE Testing ----------------\n"
            + "CONSTANTS k, k2, k3 \n"
            + "ASSUME k = <<k2, <<k3>> >> /\\ k3 = TRUE /\\ k2 = 1\n"
            + "=================================";

    TestTypeChecker t = TestUtil.typeCheckString(module);
    assertEquals("INTEGER*POW(INTEGER*BOOL)", t.getConstantType("k").toString());
    assertEquals("INTEGER", t.getConstantType("k2").toString());
    assertEquals("BOOL", t.getConstantType("k3").toString());
  }