public void CreateUnaryExpression()
        {
            IExpression valueExpression = new ConstantExpression(1);
            UnaryExpression expression = new ArithmeticUnaryExpression(ArithmeticOperator.Minus, valueExpression);

            Assert.IsTrue(expression.Expression == valueExpression);
        }
        public void CreateBinaryExpression()
        {
            IExpression leftExpression = new ConstantExpression(1);
            IExpression rightExpression = new ConstantExpression(2);
            BinaryExpression expression = new ArithmeticBinaryExpression(ArithmeticOperator.Add, leftExpression, rightExpression);

            Assert.IsTrue(expression.LeftExpression == leftExpression);
            Assert.IsTrue(expression.RightExpression == rightExpression);
        }
Пример #3
0
        public void ExecuteForEachCommand()
        {
            IExpression addToX = new ArithmeticBinaryExpression(ArithmeticOperator.Add, new VariableExpression("b"), new VariableExpression("a"));
            ICommand setX = new SetVariableCommand("a", addToX);
            IExpression values = new ConstantExpression(new int [] { 1, 2, 3 } );

            ForEachCommand foreachcmd = new ForEachCommand("b", values, setX);

            Context context = new Context();

            context.SetValue("a", 0);

            foreachcmd.Execute(context);

            Assert.AreEqual(6, context.GetValue("a"));
        }
        public void EvaluateStringConstantExpression()
        {
            ConstantExpression expression = new ConstantExpression("One");

            Assert.AreEqual("One", expression.Evaluate(null));
        }
        public void CreateIntegerConstantExpression()
        {
            ConstantExpression expression = new ConstantExpression(1);

            Assert.AreEqual(1, expression.Value);
        }
Пример #6
0
        public void ExecuteIfCommandWhenTrue()
        {
            IExpression condition = new ConstantExpression(true);
            ICommand setCommand = new SetVariableCommand("a", new ConstantExpression(1));
            IfCommand command = new IfCommand(condition, setCommand);

            Context context = new Context();

            command.Execute(context);

            Assert.AreEqual(1, context.GetValue("a"));
        }
Пример #7
0
        public void ExecuteIfCommandElseWhenFalse()
        {
            IExpression condition = new ConstantExpression(false);
            ICommand setXCommand = new SetVariableCommand("a", new ConstantExpression(1));
            ICommand setYCommand = new SetVariableCommand("b", new ConstantExpression(2));
            IfCommand command = new IfCommand(condition, setXCommand, setYCommand);

            Context context = new Context();

            command.Execute(context);

            Assert.AreEqual(Undefined.Instance, context.GetValue("a"));
            Assert.AreEqual(2, context.GetValue("b"));
        }