Ejemplo n.º 1
0
        public void MatchWithFunctionalExpression()
        {
            var expr  = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { new IntegerExpression(1), new IntegerExpression(2) });
            var expr1 = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { new IntegerExpression(1), new IntegerExpression(2) });
            var expr2 = new FunctionalExpression(new SubtractIntegersFunction(), new IExpression[] { new IntegerExpression(1), new IntegerExpression(2) });
            var expr3 = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { new IntegerExpression(2), new IntegerExpression(3) });

            Assert.IsTrue(expr.Match(expr, null));
            Assert.IsTrue(expr.Match(expr1, null));
            Assert.IsFalse(expr.Match(expr2, null));
            Assert.IsFalse(expr.Match(expr3, null));
        }
Ejemplo n.º 2
0
        public void MatchVariableInFunctionalExpression()
        {
            var one   = new IntegerExpression(1);
            var two   = new IntegerExpression(2);
            var expr  = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { new NameExpression("a"), new NameExpression("b") });
            var expr1 = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { one, two });

            Context <IExpression> ctx = new Context <IExpression>();

            Assert.IsTrue(expr.Match(expr1, ctx));

            Assert.AreSame(one, ctx.GetValue("a"));
            Assert.AreSame(two, ctx.GetValue("b"));
        }