Search in sources :

Example 46 with DeclarationNode

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

the class MachinesTest method testAOperationParameter.

@Test
public void testAOperationParameter() {
    String machine = MACHINE_NAME;
    machine += VARIABLES_X_Y;
    machine += INVARIANT_X_Y;
    machine += INITIALISATION_X_1_Y_TRUE;
    machine += "OPERATIONS foo(p) = SELECT p = 1 THEN x := p END \n";
    machine += "END";
    MachineNode machineAsSemanticAst = parseMachine(machine);
    OperationNode operationNode = machineAsSemanticAst.getOperations().get(0);
    DeclarationNode p = operationNode.getParams().get(0);
    assertEquals("p", p.getName());
    assertEquals(INTEGER, p.getType().toString());
}
Also used : OperationNode(de.bmoth.parser.ast.nodes.OperationNode) DeclarationNode(de.bmoth.parser.ast.nodes.DeclarationNode) MachineNode(de.bmoth.parser.ast.nodes.MachineNode) Test(org.junit.Test)

Example 47 with DeclarationNode

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

the class MachinesTest method testAnySubstitution.

@Test
public void testAnySubstitution() {
    String machine = MACHINE_NAME;
    machine += VARIABLES_X_Y;
    machine += INVARIANT_X_Y;
    machine += INITIALISATION_X_1_Y_TRUE;
    machine += "OPERATIONS foo = ANY p WHERE 1=1 THEN x := p END \n";
    machine += "END";
    MachineNode machineAsSemanticAst = parseMachine(machine);
    AnySubstitutionNode any = (AnySubstitutionNode) machineAsSemanticAst.getOperations().get(0).getSubstitution();
    DeclarationNode p = any.getParameters().get(0);
    assertEquals("p", p.getName());
    assertEquals(INTEGER, p.getType().toString());
}
Also used : AnySubstitutionNode(de.bmoth.parser.ast.nodes.AnySubstitutionNode) DeclarationNode(de.bmoth.parser.ast.nodes.DeclarationNode) MachineNode(de.bmoth.parser.ast.nodes.MachineNode) Test(org.junit.Test)

Example 48 with DeclarationNode

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

the class OperatorCoverageTest method testPredicateFormula.

@Test
public void testPredicateFormula() {
    String formula = "a * b = x & b = 1";
    FormulaNode formulaNode = parseFormula(formula);
    assertEquals(PREDICATE_FORMULA, formulaNode.getFormulaType());
    DeclarationNode node1 = formulaNode.getImplicitDeclarations().get(0);
    DeclarationNode node2 = formulaNode.getImplicitDeclarations().get(1);
    assertEquals("a", node1.getName());
    assertEquals("b", node2.getName());
    assertEquals(INTEGER, node1.getType().toString());
    assertEquals(INTEGER, node2.getType().toString());
}
Also used : FormulaNode(de.bmoth.parser.ast.nodes.FormulaNode) DeclarationNode(de.bmoth.parser.ast.nodes.DeclarationNode) Test(org.junit.Test)

Example 49 with DeclarationNode

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

the class NumbersTest method lessTest.

@Test
public void lessTest() throws ParserException {
    String formula = "x > 2";
    FormulaNode formulaNode = Parser.getFormulaAsSemanticAst(formula);
    assertEquals(PREDICATE_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 50 with DeclarationNode

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

the class NumbersTest method differenceTest.

@Test
public void differenceTest() throws ParserException {
    String formula = "x = 2 - 3";
    FormulaNode formulaNode = Parser.getFormulaAsSemanticAst(formula);
    assertEquals(PREDICATE_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)

Aggregations

DeclarationNode (de.bmoth.parser.ast.nodes.DeclarationNode)93 Test (org.junit.Test)92 FormulaNode (de.bmoth.parser.ast.nodes.FormulaNode)91 Ignore (org.junit.Ignore)27 MachineNode (de.bmoth.parser.ast.nodes.MachineNode)2 ParserException (de.bmoth.parser.ParserException)1 AnySubstitutionNode (de.bmoth.parser.ast.nodes.AnySubstitutionNode)1 OperationNode (de.bmoth.parser.ast.nodes.OperationNode)1 HashMap (java.util.HashMap)1