private static ExpressionInfo <Func <int, int, int> > CreateSumExprInfo() { var aExp = ExpressionInfo.Parameter(typeof(int), "a"); var bExp = ExpressionInfo.Parameter(typeof(int), "b"); return(ExpressionInfo.Lambda <Func <int, int, int> >( ExpressionInfo.Add(aExp, bExp), aExp, bExp)); }
public void Can_sum_with_ExprInfo() { var a = ExpressionInfo.Parameter(typeof(int), "a"); var b = ExpressionInfo.Parameter(typeof(int), "b"); var expr = ExpressionInfo.Lambda <Func <int, int, int> >(ExpressionInfo.Add(a, b), a, b); var sumFunc = expr.CompileFast(true); Assert.IsNotNull(sumFunc); Assert.AreEqual(sumFunc(1, 3), 4); }
private TaskInfo SearchForTestTargetAndMove(TaskInputInfo unitIndexInput, TaskInputInfo playerIndexInput) { TaskInfo pathVar = TaskInfo.Var(); TaskInfo searhForPathTask = TaskInfo.SearchForPath(TaskType.TEST_SearchForWall, pathVar, unitIndexInput); ExpressionInfo pathFound = ExpressionInfo.TaskSucceded(searhForPathTask); TaskInputInfo pathInput = new TaskInputInfo(pathVar, 0); TaskInfo moveTask = TaskInfo.Move(unitIndexInput, pathInput); return(TaskInfo.Procedure( pathVar, TaskInfo.Log("search for path started"), searhForPathTask, TaskInfo.Log( ExpressionInfo.Add( ExpressionInfo.PrimitiveVal("path found ? "), pathFound) ), moveTask, TaskInfo.Return(ExpressionInfo.TaskStatus(moveTask)) )); }
public void RepeatTaskTest(TaskInfo repeatChildTask, TaskInputInfo input, int iterations, int expectedIterations, TaskEngineEvent <TaskInfo> childTaskCallback = null, Action pass = null) { Assert.DoesNotThrow(() => { BeginTest(TestEnv0, 4); }); ExpressionInfo setToZero = ExpressionInfo.Val(PrimitiveContract.Create(0)); ExpressionInfo add = ExpressionInfo.Add( ExpressionInfo.Val(input), ExpressionInfo.Val(PrimitiveContract.Create(1))); ExpressionInfo lessThanValue = ExpressionInfo.Lt( ExpressionInfo.Val(input), ExpressionInfo.Val(PrimitiveContract.Create(iterations))); TaskInfo setToZeroTask = new TaskInfo { TaskType = TaskType.EvalExpression, OutputsCount = 1, Expression = setToZero, }; input.OutputTask = setToZeroTask; ExpressionInfo increment = ExpressionInfo.Assign(setToZeroTask, add); TaskInfo incrementTask = new TaskInfo { TaskType = TaskType.EvalExpression, Expression = increment, OutputsCount = 1, Inputs = new[] { input }, }; TaskInfo repeatTask = new TaskInfo(); repeatTask.TaskType = TaskType.Repeat; repeatTask.Expression = lessThanValue; repeatTask.Children = new[] { repeatChildTask, incrementTask }; TaskInfo task = new TaskInfo { TaskType = TaskType.Sequence, Children = new[] { setToZeroTask, repeatTask } }; task.SetParents(); const int playerId = 1; task.Initialize(playerId); // //input.SetScope(); bool isIncremented = false; BeginCleanupCheck(playerId); FinializeTest(playerId, task, result => { Assert.IsTrue(isIncremented); Assert.AreEqual(TaskState.Completed, result.State); Assert.IsFalse(result.IsFailed); CleanupCheck(playerId); if (pass != null) { pass(); } Assert.Pass(); }, childTask => { if (childTask.TaskId == repeatTask.TaskId && childTask.State == TaskState.Completed) { ITaskMemory memory = m_engine.GetTaskEngine(playerId).Memory; Assert.AreEqual(expectedIterations, memory.ReadOutput(setToZeroTask.Parent.TaskId, setToZeroTask.TaskId, 0)); isIncremented = true; } else { if (childTaskCallback != null) { childTaskCallback(childTask); } } }); }
public void IncrementTaskTest() { Assert.DoesNotThrow(() => { BeginTest(TestEnv0, 4); }); TaskInputInfo input = new TaskInputInfo { OutputIndex = 0 }; ExpressionInfo setToZero = ExpressionInfo.Val(PrimitiveContract.Create(0)); ExpressionInfo add = ExpressionInfo.Add( ExpressionInfo.Val(input), ExpressionInfo.Val(PrimitiveContract.Create(1))); TaskInfo setToZeroTask = new TaskInfo { TaskType = TaskType.EvalExpression, OutputsCount = 1, Expression = setToZero, }; ExpressionInfo increment = ExpressionInfo.Assign(setToZeroTask, add); TaskInfo incrementTask = new TaskInfo { TaskType = TaskType.EvalExpression, Expression = increment, OutputsCount = 1, Inputs = new[] { input }, }; TaskInfo task = new TaskInfo { TaskType = TaskType.Sequence, Children = new[] { setToZeroTask, incrementTask } }; task.SetParents(); input.OutputTask = setToZeroTask; input.SetScope(); bool isIncremented = false; const int playerId = 1; BeginCleanupCheck(playerId); FinializeTest(playerId, task, result => { Assert.IsTrue(isIncremented); Assert.AreEqual(TaskState.Completed, result.State); Assert.IsFalse(result.IsFailed); CleanupCheck(playerId); Assert.Pass(); }, childTask => { if (childTask.TaskId == incrementTask.TaskId && childTask.State == TaskState.Completed) { ITaskMemory memory = m_engine.GetTaskEngine(playerId).Memory; Assert.AreEqual(1, memory.ReadOutput(setToZeroTask.Parent.TaskId, setToZeroTask.TaskId, 0)); isIncremented = true; } }); }