当前位置: 首页>>代码示例>>C#>>正文


C# Machine.Run方法代码示例

本文整理汇总了C#中Machine.Run方法的典型用法代码示例。如果您正苦于以下问题:C# Machine.Run方法的具体用法?C# Machine.Run怎么用?C# Machine.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Machine的用法示例。


在下文中一共展示了Machine.Run方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GivenInitiallyTrueCondition_WhenWhileIsEvaluated_BodyIsEvaluatedUntilConditionBecomesFalse

        public void GivenInitiallyTrueCondition_WhenWhileIsEvaluated_BodyIsEvaluatedUntilConditionBecomesFalse()
        {
            var whileStatement = CreateWhileStatement();

            var environment = Environment.Empty;
            environment = environment.AddValue("x", new Number(1));

            var machine = new Machine(whileStatement, environment);
            machine.Run();

            var finalEnvironment = machine.Environment;
            finalEnvironment.GetValue<int>("x").Value.Should().Be(8, "because the body was executed three times");
        }
开发者ID:vgrigoriu,项目名称:UnderstandingComputation,代码行数:13,代码来源:WhileTests.cs

示例2: GivenFalseCondition_WhenWhileIsEvaluated_NothingHappens

        public void GivenFalseCondition_WhenWhileIsEvaluated_NothingHappens()
        {
            var whileStatement = CreateWhileStatement();

            var environment = Environment.Empty;
            environment = environment.AddValue("x", new Number(7));

            var machine = new Machine(whileStatement, environment);
            machine.Run();

            var finalEnvironment = machine.Environment;
            finalEnvironment.GetValue<int>("x").Value.Should().Be(7, "because the condition was false so the body was never executed");
        }
开发者ID:vgrigoriu,项目名称:UnderstandingComputation,代码行数:13,代码来源:WhileTests.cs

示例3: GivenAReducibleStatement_WhenRunIsCalled_TheStatementIsReduced

        public void GivenAReducibleStatement_WhenRunIsCalled_TheStatementIsReduced()
        {
            var environment = Environment.Empty;

            var statement = new Assign<int>(
                new Variable<int>("q"),
                new Number(1));

            var machine = new Machine(statement, environment);

            machine.Run();

            machine.Statement.IsReducible.Should().BeFalse();
        }
开发者ID:vgrigoriu,项目名称:UnderstandingComputation,代码行数:14,代码来源:MachineTests.cs

示例4: GivenAnIfStatement_WhenConditionIsTrue_ThenConsequenceIsExecuted

        public void GivenAnIfStatement_WhenConditionIsTrue_ThenConsequenceIsExecuted()
        {
            var ifStatement = CreateIfStatement();

            var environment = CreateBaseEnvironment();
            environment = environment.AddValue("x", new Number(-1));

            var machine = new Machine(ifStatement, environment);
            machine.Run();

            var finalEnvironment = machine.Environment;
            finalEnvironment.GetValue<int>("a").Value.Should().Be(1, "because the consequence was executed");
            finalEnvironment.GetValue<int>("b").Value.Should().Be(0, "because the alternative was not executed");
        }
开发者ID:vgrigoriu,项目名称:UnderstandingComputation,代码行数:14,代码来源:IfTests.cs

示例5: GivenASequence_WhenItIsRun_BothStatementsAreExecuted

        public void GivenASequence_WhenItIsRun_BothStatementsAreExecuted()
        {
            var first = new Assign<int>(new Variable<int>("x"), new Add(new Number(1), new Number(2)));
            var second = new Assign<int>(new Variable<int>("y"), new Add(new Number(3), new Number(4)));

            var sequence = new Sequence(first, second);

            var machine = new Machine(sequence, Environment.Empty);
            machine.Run();
            var finalEnvironment = machine.Environment;

            finalEnvironment.GetValue<int>("x").Value.Should().Be(3, "the first statement was executed");
            finalEnvironment.GetValue<int>("y").Value.Should().Be(7, "the second statement was executed");
        }
开发者ID:vgrigoriu,项目名称:UnderstandingComputation,代码行数:14,代码来源:SequenceTests.cs

示例6: Main

        static void Main(string[] args)
        {
            var environment = Environment.Empty;
            environment = environment.AddValue("x", new Number(3));
            environment = environment.AddValue("y", new Number(4));

            var statement = new Assign<int>(
                new Variable<int>("x"),
                new Add(
                    new Variable<int>("x"),
                    new Variable<int>("y")));

            var machine = new Machine(statement, environment);

            machine.Run();
        }
开发者ID:vgrigoriu,项目名称:UnderstandingComputation,代码行数:16,代码来源:Program.cs

示例7: GivenAComplexStatement_WhenTheMachineIsRun_TheStatementIsExecuted

        public void GivenAComplexStatement_WhenTheMachineIsRun_TheStatementIsExecuted()
        {
            var environment = Environment.Empty;
            environment = environment.AddValue("x", new Number(3));
            environment = environment.AddValue("y", new Number(4));

            // x = x + y
            var statement = new Assign<int>(
                new Variable<int>("x"),
                new Add(
                    new Variable<int>("x"),
                    new Variable<int>("y")));

            var machine = new Machine(statement, environment);

            machine.Run();

            machine.Environment.GetValue<int>("x").Value.Should().Be(7);
        }
开发者ID:vgrigoriu,项目名称:UnderstandingComputation,代码行数:19,代码来源:MachineTests.cs


注:本文中的Machine.Run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。