Search in sources :

Example 1 with FormulaNode

use of de.bmoth.parser.ast.nodes.FormulaNode in project bmoth by hhu-stups.

the class OperatorCoverageTest method testExpressionFormula.

@Test
public void testExpressionFormula() {
    String formula = "x - 2 / 3";
    FormulaNode formulaNode = parseFormula(formula);
    assertEquals(EXPRESSION_FORMULA, formulaNode.getFormulaType());
    DeclarationNode declarationNode = formulaNode.getImplicitDeclarations().get(0);
    assertEquals("x", declarationNode.getName());
    assertEquals(INTEGER, declarationNode.getType().toString());
}
Also used : FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) DeclarationNode(de.bmoth.parser.ast.nodes.DeclarationNode) Test(org.junit.Test)

Example 2 with FormulaNode

use of de.bmoth.parser.ast.nodes.FormulaNode in project bmoth by hhu-stups.

the class TestTypechecker method getFormulaTypes.

public static Map<String, String> getFormulaTypes(String formula) {
    FormulaNode formulaNode;
    try {
        formulaNode = Parser.getFormulaAsSemanticAst(formula);
        HashMap<String, String> map = new HashMap<>();
        for (DeclarationNode decl : formulaNode.getImplicitDeclarations()) {
            map.put(decl.getName(), decl.getType().toString());
        }
        return map;
    } catch (ParserException e) {
        fail(e.getMessage());
        return null;
    }
}
Also used : ParserException(de.bmoth.parser.ParserException) FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) HashMap(java.util.HashMap) DeclarationNode(de.bmoth.parser.ast.nodes.DeclarationNode)

Example 3 with FormulaNode

use of de.bmoth.parser.ast.nodes.FormulaNode in project bmoth by hhu-stups.

the class ASTTransformationTest method testElementOfCombinedWithIntersection.

@Test
public void testElementOfCombinedWithIntersection() {
    String formula = "a : {1} /\\ b";
    FormulaNode formulaNode = parseFormula(formula);
    formulaNode = AstTransformationsForZ3.transformFormulaNode(formulaNode);
    assertEquals("AND(ELEMENT_OF(a,SET_ENUMERATION(1)),ELEMENT_OF(a,b))", formulaNode.getFormula().toString());
}
Also used : FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) Test(org.junit.Test)

Example 4 with FormulaNode

use of de.bmoth.parser.ast.nodes.FormulaNode in project bmoth by hhu-stups.

the class ASTTransformationTest method testMemberOfIntervalToLeqGeq.

@Test
public void testMemberOfIntervalToLeqGeq() {
    String formula = "a : 1..7";
    FormulaNode formulaNode = parseFormula(formula);
    formulaNode = AstTransformationsForZ3.transformFormulaNode(formulaNode);
    assertEquals("AND(GREATER_EQUAL(a,1),LESS_EQUAL(a,7))", formulaNode.getFormula().toString());
}
Also used : FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) Test(org.junit.Test)

Example 5 with FormulaNode

use of de.bmoth.parser.ast.nodes.FormulaNode in project bmoth by hhu-stups.

the class ASTTransformationTest method testMemberOfIntervalInsideQuantifiersToLeqGeq.

@Test
public void testMemberOfIntervalInsideQuantifiersToLeqGeq() {
    String formula = "!(a) . (a : 1..7)";
    FormulaNode formulaNode = parseFormula(formula);
    formulaNode = AstTransformationsForZ3.transformFormulaNode(formulaNode);
    assertEquals("FORALL(a,AND(GREATER_EQUAL(a,1),LESS_EQUAL(a,7)))", formulaNode.getFormula().toString());
    formula = "#(a) . (a : 1..7)";
    formulaNode = parseFormula(formula);
    formulaNode = AstTransformationsForZ3.transformFormulaNode(formulaNode);
    assertEquals("EXISTS(a,AND(GREATER_EQUAL(a,1),LESS_EQUAL(a,7)))", formulaNode.getFormula().toString());
}
Also used : FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) Test(org.junit.Test)

Aggregations

FormulaNode (de.bmoth.parser.ast.nodes.FormulaNode)106 Test (org.junit.Test)102 DeclarationNode (de.bmoth.parser.ast.nodes.DeclarationNode)91 Ignore (org.junit.Ignore)27 ParserException (de.bmoth.parser.ParserException)2 BMoThParser (de.bmoth.antlr.BMoThParser)1 FormulaContext (de.bmoth.antlr.BMoThParser.FormulaContext)1 SemanticAstCreator (de.bmoth.parser.ast.SemanticAstCreator)1 TypeErrorException (de.bmoth.parser.ast.TypeErrorException)1 ViewModel (de.saxsys.mvvmfx.ViewModel)1 HashMap (java.util.HashMap)1