public void SelfReferenceSubstituteTest() { var ast1 = new ArithmExprNode(1, new IdNode(1, "x"), ArithmOpNode.FromSymbol(1, "+"), new ArithmExprNode(1, new IdNode(1, "y"), ArithmOpNode.FromSymbol(1, "+"), new IdNode(1, "x") ) ); var repl = new ArithmExprNode(1, new IdNode(1, "y"), new ArithmOpNode(1, "-", BinaryOperations.ArithmeticFromSymbol("-")), new IdNode(1, "x") ); var ast2 = new ArithmExprNode(1, new IdNode(1, "x"), ArithmOpNode.FromSymbol(1, "+"), new ArithmExprNode(1, repl, ArithmOpNode.FromSymbol(1, "+"), new IdNode(1, "x") ) ); Assert.That(ast1.Substitute(new IdNode(2, "y"), repl), Is.EqualTo(ast2)); }
public void ExpressionSubstituteTest() { var ast1 = new ArithmExprNode(1, new IdNode(1, "x"), ArithmOpNode.FromSymbol(1, "+"), new IdNode(1, "x") ); var ast2 = new ArithmExprNode(1, new LitExprNode(1, 1), ArithmOpNode.FromSymbol(1, "+"), new LitExprNode(1, 1) ); Assert.That(ast1.Substitute(new IdNode(2, "x"), new LitExprNode(2, 1)), Is.EqualTo(ast2)); }