<commit_before>package de.bmoth.parser.ast.nodes;

import de.bmoth.parser.ast.nodes.FormulaNode.FormulaType;
import org.junit.Test;

import java.util.ArrayList;

import static de.bmoth.parser.ast.nodes.ExpressionOperatorNode.ExpressionOperator.DOMAIN;
import static de.bmoth.parser.ast.nodes.FormulaNode.FormulaType.EXPRESSION_FORMULA;
import static de.bmoth.parser.ast.nodes.FormulaNode.FormulaType.PREDICATE_FORMULA;
import static de.bmoth.parser.ast.nodes.PredicateOperatorNode.PredicateOperator.AND;
import static de.bmoth.parser.ast.nodes.QuantifiedExpressionNode.QuantifiedExpressionOperator.SET_COMPREHENSION;
import static de.bmoth.parser.ast.nodes.QuantifiedPredicateNode.QuantifiedPredicateOperator.EXISTENTIAL_QUANTIFICATION;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static de.bmoth.TestParser.*;
public class NodeTest {
    @Test
    public void testOperationNode() {
        MachineNode machine = parseMachine(
            "MACHINE OpNodeMachine\nVARIABLES x\nPROPERTIES 1=1\nINVARIANT x:INTEGER\nOPERATIONS\n\tset = BEGIN x := 1 END;\n\tselect = SELECT x = 1 THEN x := x END\nEND");
        OperationNode setOperation = machine.getOperations().get(0);
        OperationNode selectOperation = machine.getOperations().get(1);
        assertEquals("set", setOperation.getName());
        assertEquals("set = BEGIN x := 1 END", setOperation.toString());
        assertEquals("select = SELECT EQUAL(x,1) THEN x := x END", selectOperation.toString());
        assertEquals("[x]", setOperation.getAssignedDeclarationNodes().toString());
    }

    @Test
    public void testPredicateOperatorNode() {
        PredicateOperatorNode andNode = (PredicateOperatorNode) parseFormula("x & y").getFormula();
        Node orNode = parseFormula("x or y").getFormula();
        Node trueNode = parseFormula("TRUE").getFormula();

        assertEquals("AND(x,y)", andNode.toString());
        assertEquals("OR(x,y)", orNode.toString());
        assertEquals("TRUE", trueNode.toString());
        assertEquals(AND, PredicateOperatorNode.PredicateOperator.valueOf("AND"));
    }

    @Test
    public void testPredicateOperatorWithExprArgsNode() {
        PredicateOperatorWithExprArgsNode equalNode = (PredicateOperatorWithExprArgsNode) parseFormula("x = 1").getFormula();
<commit_msg>added test for better coverage<commit_after>package de.bmoth.parser.ast.nodes;

import de.bmoth.parser.ast.nodes.FormulaNode.FormulaType;
import org.junit.Test;

import java.util.ArrayList;

import static de.bmoth.parser.ast.nodes.ExpressionOperatorNode.ExpressionOperator.DOMAIN;
import static de.bmoth.parser.ast.nodes.FormulaNode.FormulaType.EXPRESSION_FORMULA;
import static de.bmoth.parser.ast.nodes.FormulaNode.FormulaType.PREDICATE_FORMULA;
import static de.bmoth.parser.ast.nodes.PredicateOperatorNode.PredicateOperator.AND;
import static de.bmoth.parser.ast.nodes.QuantifiedExpressionNode.QuantifiedExpressionOperator.SET_COMPREHENSION;
import static de.bmoth.parser.ast.nodes.QuantifiedPredicateNode.QuantifiedPredicateOperator.EXISTENTIAL_QUANTIFICATION;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static de.bmoth.TestParser.*;
public class NodeTest {

    @Test
    public void testConditionSubstitutionNode() {
        MachineNode machine = parseMachine("MACHINE CondSubstNodeMachine\n" +
            "VARIABLES x\n" +
            "INVARIANT x:INTEGER\n" +
            "INITIALISATION\n" +
            "\tx := 1\n" +
            "OPERATIONS\n" +
            "\tcondOp1 = SELECT x = 1 THEN x := 2 END;\n" +
            "\tcondOp2 = SELECT x = 25 THEN x := 5000 END\n" +
            "END");

        SelectSubstitutionNode condSub1 = (SelectSubstitutionNode) machine.getOperations().get(0).getSubstitution();
        SelectSubstitutionNode condSub2 = (SelectSubstitutionNode) machine.getOperations().get(1).getSubstitution();
        ConditionSubstitutionNode newCondSub = new ConditionSubstitutionNode(condSub1.getConditions().get(0), condSub2.getSubstitutions().get(0));

        assertEquals("SELECT EQUAL(x,1) THEN x := 5000 END", newCondSub.toString());

        newCondSub.setCondition(condSub2.getConditions().get(0));
        newCondSub.setSubstitution(condSub1.getSubstitutions().get(0));
        assertEquals("SELECT EQUAL(x,25) THEN x := 2 END", newCondSub.toString());
    }

    @Test
    public void testOperationNode() {
        MachineNode machine = parseMachine(
            "MACHINE OpNodeMachine\nVARIABLES x\nPROPERTIES 1=1\nINVARIANT x:INTEGER\nOPERATIONS\n\tset = BEGIN x := 1 END;\n\tselect = SELECT x = 1 THEN x := x END\nEND");
        OperationNode setOperation = machine.getOperations().get(0);
        OperationNode selectOperation = machine.getOperations().get(1);
        assertEquals("set", setOperation.getName());
        assertEquals("set = BEGIN x := 1 END", setOperation.toString());
        assertEquals("select = SELECT EQUAL(x,1) THEN x := x END", selectOperation.toString());
        assertEquals("[x]", setOperation.getAssignedDeclarationNodes().toString());
    }

    @Test
    public void testPredicateOperatorNode() {
        PredicateOperatorNode andNode = (PredicateOperatorNode) parseFormula("x & y").getFormula();
        Node orNode = parseFormula("x or y").getFormula();
        Node trueNode = parseFormula("TRUE").getFormula();

        assertEquals("AND(x,y)", andNode.toString());
        assertEquals("OR(x,y)", orNode.toString());
        assertEquals("TRUE", trueNode.toString());
        assertEquals(AND, PredicateOperatorNode.PredicateOperator.valueOf("AND"));
    }

    @Test
    public void testPredicateOperatorWithExprArgsNode() {
        PredicateOperatorWithExprArgsNode equalNode = (PredicateOperatorWithExprArgsNode) parseFormula("x = 1").getFormula();

{'fraction_non_alphanumeric': 0.11914966569518258, 'fraction_numerical': 0.008400480027430138, 'mean_word_length': 4.274864376130199, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2009340', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1678, 'n_words': 304}