Exemplo n.º 1
0
        public void ExpreessionInfoCloneTest2()
        {
            ExpressionInfo canRun = ExpressionInfo.Eq(
                ExpressionInfo.PrimitiveVal(CmdResultCode.Success),
                ExpressionInfo.Val(new TaskInputInfo()));

            Assert.DoesNotThrow(() =>
            {
                TaskInfo task = new TaskInfo {
                    Expression = canRun
                };
                byte[] b = m_protobufSerializer.Serialize(SerializedTask.FromTaskInfo(task));
                SerializedTask.ToTaskInfo(m_protobufSerializer.Deserialize <SerializedTask>(b));
            });
        }
Exemplo n.º 2
0
        public void RepeatBreakTaskTest()
        {
            TaskInputInfo input = new TaskInputInfo {
                OutputIndex = 0
            };
            ExpressionInfo eqTo5 = ExpressionInfo.Eq(
                ExpressionInfo.Val(input),
                ExpressionInfo.Val(PrimitiveContract.Create(5)));
            TaskInfo branchTask = new TaskInfo
            {
                TaskType   = TaskType.Branch,
                Expression = eqTo5,
                Children   = new[]
                {
                    new TaskInfo
                    {
                        TaskType = TaskType.Break,
                    },
                    null
                }
            };

            RepeatTaskTest(branchTask, input, 10, 5);
        }
Exemplo n.º 3
0
        public void IterateRepeatTest()
        {
            Assert.DoesNotThrow(() =>
            {
                BeginTest(TestEnv0, 4);
            });

            List <int> integers = new List <int>()
            {
                1, 2, 3, 4, 5
            };
            TaskInfo iterateTask = new TaskInfo
            {
                TaskType     = TaskType.EvalExpression,
                Expression   = ExpressionInfo.Iterate(integers),
                OutputsCount = 1,
            };

            TaskInputInfo input = new TaskInputInfo
            {
                OutputIndex = 0,
                OutputTask  = iterateTask,
            };

            ExpressionInfo isTrue = ExpressionInfo.Eq(
                ExpressionInfo.Val(PrimitiveContract.Create(true)),
                ExpressionInfo.Get(
                    ExpressionInfo.Val(input),
                    ExpressionInfo.PrimitiveVal("IsLast")));

            TaskInfo breakIfCompleted = new TaskInfo
            {
                TaskType   = TaskType.Branch,
                Expression = isTrue,
                Children   = new[]
                {
                    new TaskInfo
                    {
                        TaskType = TaskType.Break,
                    },
                    null
                }
            };

            TaskInfo repeat = new TaskInfo
            {
                TaskType   = TaskType.Repeat,
                Expression = ExpressionInfo.PrimitiveVal(true),
                Children   = new[]
                {
                    iterateTask,
                    breakIfCompleted,
                }
            };

            repeat.SetParents();
            input.SetScope();

            const int playerId   = 1;
            bool      isIterated = false;
            int       counter    = 0;

            BeginCleanupCheck(playerId);

            FinializeTest(playerId, repeat, result =>
            {
                Assert.IsTrue(isIterated);

                Assert.AreEqual(TaskState.Completed, result.State);
                Assert.IsFalse(result.IsFailed);
                CleanupCheck(playerId);

                Assert.Pass();
            },
                          childTask =>
            {
                if (childTask.TaskId == iterateTask.TaskId && childTask.State == TaskState.Completed)
                {
                    counter++;
                    ITaskMemory memory         = m_engine.GetTaskEngine(playerId).Memory;
                    IterationResult iterResult = (IterationResult)memory.ReadOutput(iterateTask.Parent.TaskId, iterateTask.TaskId, 0);
                    if (iterResult.IsLast)
                    {
                        isIterated = true;
                        Assert.IsNull(iterResult.Object);
                    }
                    else
                    {
                        Assert.AreEqual(counter, (int)iterResult.Object);
                    }
                }
            });
        }