コード例 #1
0
ファイル: HostTests.cs プロジェクト: ajlopez/AjSharp
        public void ExecuteSetCommand()
        {
            SetVariableCommand command = new SetVariableCommand("foo", new ConstantExpression("bar"));
            this.host.Execute(command);

            Assert.AreEqual("bar", this.host.Machine.Environment.GetValue("foo"));
        }
コード例 #2
0
ファイル: CommandsTests.cs プロジェクト: ajlopez/AjSharp
        public void ExecuteForCommand()
        {
            ICommand setX = new SetVariableCommand("x", new ConstantExpression(0));
            ICommand setY = new SetVariableCommand("y", new ConstantExpression(0));
            List<ICommand> commands = new List<ICommand>();
            commands.Add(setX);
            commands.Add(setY);
            ICommand initialCommand = new CompositeCommand(commands);

            IExpression condition = new CompareExpression(ComparisonOperator.Less, new VariableExpression("x"), new ConstantExpression(6));

            IExpression addXtoY = new ArithmeticBinaryExpression(ArithmeticOperator.Add, new VariableExpression("y"), new VariableExpression("x"));
            ICommand addToY = new SetVariableCommand("y", addXtoY);

            ICommand endCommand = new SetVariableCommand("x", new ArithmeticBinaryExpression(ArithmeticOperator.Add, new VariableExpression("x"), new ConstantExpression(1)));

            ForCommand forcmd = new ForCommand(initialCommand, condition, endCommand, addToY);

            BindingEnvironment environment = new BindingEnvironment();

            environment.SetValue("y", null);

            forcmd.Execute(environment);

            Assert.AreEqual(15, environment.GetValue("y"));
        }
コード例 #3
0
ファイル: CommandsTests.cs プロジェクト: ajlopez/AjSharp
        public void ExecuteCompositeCommand()
        {
            BindingEnvironment environment = new BindingEnvironment();

            SetVariableCommand command1 = new SetVariableCommand("foo", new ConstantExpression("bar"));
            SetVariableCommand command2 = new SetVariableCommand("one", new ConstantExpression(1));
            SetVariableCommand command3 = new SetVariableCommand("bar", new VariableExpression("foo"));

            List<ICommand> commands = new List<ICommand>();
            commands.Add(command1);
            commands.Add(command2);
            commands.Add(command3);

            CompositeCommand command = new CompositeCommand(commands);

            environment.SetValue("foo", null);
            environment.SetValue("one", null);

            command.Execute(environment);

            Assert.AreEqual("bar", environment.GetValue("foo"));
            Assert.AreEqual(1, environment.GetValue("one"));
            Assert.AreEqual("bar", environment.GetValue("bar"));
        }
コード例 #4
0
ファイル: CommandsTests.cs プロジェクト: ajlopez/AjSharp
        public void ExecuteWhileCommand()
        {
            IExpression incrementX = new ArithmeticBinaryExpression(ArithmeticOperator.Add, new ConstantExpression(1), new VariableExpression("x"));
            IExpression decrementY = new ArithmeticBinaryExpression(ArithmeticOperator.Subtract, new VariableExpression("y"), new ConstantExpression(1));
            ICommand setX = new SetVariableCommand("x", incrementX);
            ICommand setY = new SetVariableCommand("y", decrementY);
            List<ICommand> commands = new List<ICommand>();
            commands.Add(setX);
            commands.Add(setY);
            ICommand command = new CompositeCommand(commands);
            IExpression yexpr = new VariableExpression("y");

            WhileCommand whilecmd = new WhileCommand(yexpr, command);

            BindingEnvironment environment = new BindingEnvironment();

            environment.SetValue("x", 0);
            environment.SetValue("y", 5);

            whilecmd.Execute(environment);

            Assert.AreEqual(0, environment.GetValue("y"));
            Assert.AreEqual(5, environment.GetValue("x"));
        }
コード例 #5
0
ファイル: CommandsTests.cs プロジェクト: ajlopez/AjSharp
        public void ExecuteSetVariableCommand()
        {
            BindingEnvironment environment = new BindingEnvironment();
            SetVariableCommand command = new SetVariableCommand("foo", new ConstantExpression("bar"));

            command.Execute(environment);

            Assert.AreEqual("bar", environment.GetValue("foo"));
        }
コード例 #6
0
ファイル: CommandsTests.cs プロジェクト: ajlopez/AjSharp
        public void ExecuteIfCommandWhenTrue()
        {
            IExpression condition = new ConstantExpression(true);
            ICommand setCommand = new SetVariableCommand("x", new ConstantExpression(1));
            IfCommand command = new IfCommand(condition, setCommand);

            BindingEnvironment environment = new BindingEnvironment();

            command.Execute(environment);

            Assert.AreEqual(1, environment.GetValue("x"));
        }
コード例 #7
0
ファイル: CommandsTests.cs プロジェクト: ajlopez/AjSharp
        public void ExecuteIfCommandElseWhenFalse()
        {
            IExpression condition = new ConstantExpression(false);
            ICommand setXCommand = new SetVariableCommand("x", new ConstantExpression(1));
            ICommand setYCommand = new SetVariableCommand("y", new ConstantExpression(2));
            IfCommand command = new IfCommand(condition, setXCommand, setYCommand);

            BindingEnvironment environment = new BindingEnvironment();

            command.Execute(environment);

            Assert.IsNull(environment.GetValue("x"));
            Assert.AreEqual(2, environment.GetValue("y"));
        }
コード例 #8
0
ファイル: CommandsTests.cs プロジェクト: ajlopez/AjSharp
        public void ExecuteForEachCommand()
        {
            IExpression addToX = new ArithmeticBinaryExpression(ArithmeticOperator.Add, new VariableExpression("y"), new VariableExpression("x"));
            ICommand setX = new SetVariableCommand("x", addToX);
            IExpression values = new ConstantExpression(new int[] { 1, 2, 3 });

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

            BindingEnvironment environment = new BindingEnvironment();

            environment.SetValue("x", 0);

            foreachcmd.Execute(environment);

            Assert.AreEqual(6, environment.GetValue("x"));
        }