public void Test_Run_PrioritySequence_With_RunningNode_DoesntReenter_Only_Running_Node(int count) { //arrange List <TreeNode <int> > nodes = new List <TreeNode <int> >(5); for (int i = 0; i < 5; i++) { nodes.Add(new TestSuccessNode()); } TestRunningNode runningNode = new TestRunningNode(); nodes.Add(runningNode); PrioritySequenceTreeNode <int> PrioritySequence = new PrioritySequenceTreeNode <int>(nodes); //act for (int i = 0; i < count; i++) { PrioritySequence.Evaluate(5); } //assert Assert.True(PrioritySequence.isRunningNode, $"The PrioritySequence should indicate that it is running."); Assert.NotNull(PrioritySequence.RunningNode, $"The PrioritySequence should have a non-null running node."); Assert.AreEqual(runningNode, PrioritySequence.RunningNode, $"The running node should be the same as the running node from construction."); foreach (var node in nodes) { Assert.AreEqual(count, ((dynamic)node).CalledTime, $"Should have called all the nodes {count} many times."); } }
public void Test_Run_Selector_With_RunningNode_Reenter_Only_Running_Node(int count) { //arrange List <TreeNode <int> > nodes = new List <TreeNode <int> >(5); for (int i = 0; i < 5; i++) { nodes.Add(new TestFailedNode()); } TestRunningNode runningNode = new TestRunningNode(); nodes.Add(runningNode); SelectorTreeNode <int> sequence = new SelectorTreeNode <int>(nodes); //act for (int i = 0; i < count; i++) { sequence.Evaluate(5); } //assert Assert.True(sequence.isRunningNode, $"The sequence should indicate that it is running."); Assert.NotNull(sequence.RunningNode, $"The sequence should have a non-null running node."); Assert.AreEqual(runningNode, sequence.RunningNode, $"The running node should be the same as the running node from construction."); foreach (var node in nodes.AsEnumerable().Reverse().Skip(1).Reverse()) { Assert.AreEqual(1, ((dynamic)node).CalledTime, $"Should only have called the non-running nodes once."); } Assert.AreEqual(count, ((dynamic)nodes.Last()).CalledTime, $"The last node (running node) should have been called every time the evaluation occured."); }