Exemplo n.º 1
0
        public void SelectorRunning()
        {
            var Selector = new SelectorNode();
            var running  = new TaskRunningNode();
            var node     = new TaskSuccessNode();

            Selector.Append(running);
            Selector.Append(node);

            Assert.That(Selector.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(Selector.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(Selector.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(Selector.Run(null), Is.EqualTo(NodeState.Running));

            Assert.That(Selector.Run(null), Is.EqualTo(NodeState.Success));
            Assert.That(node.executed, Is.EqualTo(false));  //next node in Selector will be never executed
        }
Exemplo n.º 2
0
        public void SequenceRunning_Green()
        {
            var sequence = new SequenceNode();
            var run      = new TaskRunningNode();
            var succ     = new TaskSuccessNode();

            sequence.Append(run);
            sequence.Append(succ);

            Assert.That(sequence.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(sequence.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(sequence.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(sequence.Run(null), Is.EqualTo(NodeState.Running));

            Assert.That(succ.executed, Is.EqualTo(false));                  //node not called
            Assert.That(sequence.Run(null), Is.EqualTo(NodeState.Success)); //step forward, tree unlocked, next node called
            Assert.That(succ.executed, Is.EqualTo(true));                   //condition satisfied
        }
Exemplo n.º 3
0
        public void SequenceRunning_Red()
        {
            var sequence = new SequenceNode();
            var run      = new TaskRunningNode();
            var fail     = new TaskFailureNode();
            var succ     = new TaskSuccessNode();

            sequence.Append(run);
            sequence.Append(fail);
            sequence.Append(succ);

            Assert.That(sequence.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(sequence.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(sequence.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(sequence.Run(null), Is.EqualTo(NodeState.Running));

            Assert.That(sequence.Run(null), Is.EqualTo(NodeState.Failure));

            Assert.That(fail.executed, Is.EqualTo(true));   //condition satisfied
            Assert.That(succ.executed, Is.EqualTo(false));  //condition satisfied
        }
Exemplo n.º 4
0
        public void SelectorRunningWithFailure()
        {
            var Selector = new SelectorNode();
            var failure  = new TaskFailureNode();
            var running  = new TaskRunningNode();
            var node     = new TaskSuccessNode();

            Selector.Append(failure);
            Selector.Append(running);
            Selector.Append(node);

            //same asserts as before, failure will be ignored
            Assert.That(Selector.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(Selector.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(Selector.Run(null), Is.EqualTo(NodeState.Running));
            Assert.That(Selector.Run(null), Is.EqualTo(NodeState.Running));

            Assert.That(Selector.Run(null), Is.EqualTo(NodeState.Success));
            Assert.That(failure.executed, Is.EqualTo(true));
            Assert.That(node.executed, Is.EqualTo(false));  //next node in Selector will be never executed
        }