package de.bmoth.parser.ast.nodes;

import de.bmoth.TestParser;
import org.junit.Test;

import java.util.List;
import java.util.stream.Collectors;

import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertTrue;


public class EqualAstTest extends TestParser {
    @Test
    public void testEqualAstIfSubstitution() {
        MachineNode machine = new MachineBuilder()
            .setName("IfSubstitutionMachine")
            .setVariables("a")
            .setInvariant("a : INTEGER")
            .setInitialization("a := 0")
            .addOperation("op1 = IF a = 3 THEN a:=2 ELSE a:=1 END")
            .addOperation("op2 = IF a = 3 THEN a:=2 ELSE a:=1 END")
            .addOperation("op_changed1 = IF a = 2 THEN a:=2 ELSE a:=1 END")
            .addOperation("op_changed2 = IF a = 3 THEN a:=5 ELSE a:=1 END")
            .addOperation("op_changed3 = IF a = 3 THEN a:=2 ELSE a:=3 END")
            .build();

        List<SubstitutionNode> substitutions = machine.getOperations().stream().map(OperationNode::getSubstitution).collect(Collectors.toList());
        assertTrue(substitutions.get(0).equalAst(substitutions.get(1)));
        assertFalse(substitutions.get(0).equalAst(substitutions.get(2)));
        assertFalse(substitutions.get(0).equalAst(substitutions.get(3)));
        assertFalse(substitutions.get(0).equalAst(substitutions.get(4)));
    }
}


@@ -912,24 +912,1264 @@
  a:=3 END%22)%0A
+            .addOperation(%22op_not_if = SELECT a = 3 THEN a:=2 END%22)%0A            .build();%0A%0A        List%3CSubstitutionNode%3E substitutions = machine.getOperations().stream().map(OperationNode::getSubstitution).collect(Collectors.toList());%0A        assertTrue(substitutions.get(0).equalAst(substitutions.get(1)));%0A        assertFalse(substitutions.get(0).equalAst(substitutions.get(2)));%0A        assertFalse(substitutions.get(0).equalAst(substitutions.get(3)));%0A        assertFalse(substitutions.get(0).equalAst(substitutions.get(4)));%0A        assertFalse(substitutions.get(0).equalAst(substitutions.get(5)));%0A    %7D%0A%0A    @Test%0A    public void testEqualAstSelectSubstitution() %7B%0A        MachineNode machine = new MachineBuilder()%0A            .setName(%22IfSubstitutionMachine%22)%0A            .setVariables(%22a%22)%0A            .setInvariant(%22a : INTEGER%22)%0A            .setInitialization(%22a := 0%22)%0A            .addOperation(%22op1 = SELECT a : %7B2+1%7D THEN a:=2 END%22)%0A            .addOperation(%22op2 = SELECT a : %7B2+1%7D THEN a:=2 END%22)%0A            .addOperation(%22op_changed1 = SELECT a = 3 THEN a:=2 END%22)%0A            .addOperation(%22op_changed2 = SELECT a : %7B2+1%7D THEN a:=1+1 END%22)%0A            .addOperation(%22op_not_select = IF a = 3 THEN a:=2 ELSE a:=3 END%22)%0A
             

add test