Evaluate() публичный Метод

public Evaluate ( Context context, bool withvars = false ) : object
context Context
withvars bool
Результат object
Пример #1
0
        public void RaiseIfTupleHasVariable()
        {
            Context context = new Context();
            var expr = new TupleExpression(new IExpression[] { new ConstantExpression(1), new VariableExpression(new Variable("X")), new AtomExpression(new Atom("y")) });

            try
            {
                expr.Evaluate(context);
                Assert.Fail();
            }
            catch (System.Exception ex)
            {
                Assert.AreEqual("variable 'X' is unbound", ex.Message);
            }
        }
Пример #2
0
        public void CreateEmptyTuple()
        {
            var expr = new TupleExpression(new IExpression[] { });

            Assert.IsFalse(expr.HasVariable());

            var result = expr.Evaluate(null);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Tuple));

            var tuple = (Tuple)result;

            Assert.AreEqual(0, tuple.Arity);
        }
Пример #3
0
        public void CreateSimpleTuple()
        {
            Context context = new Context();
            context.SetValue("X", 2);
            var expr = new TupleExpression(new IExpression[] { new ConstantExpression(1), new VariableExpression(new Variable("X")), new AtomExpression(new Atom("y")) });

            Assert.IsTrue(expr.HasVariable());

            var result = expr.Evaluate(context);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Tuple));

            var tuple = (Tuple)result;

            Assert.AreEqual(3, tuple.Arity);
            Assert.AreEqual(1, tuple.ElementAt(0));
            Assert.AreEqual(2, tuple.ElementAt(1));
            Assert.IsInstanceOfType(tuple.ElementAt(2), typeof(Atom));
            Assert.AreEqual("y", ((Atom)tuple.ElementAt(2)).Name);
        }