Пример #1
0
        public void Selector_AllFailures()
        {
            var root    = new SelectorNode();
            var failure = new TaskFailureNode();

            root.Append(failure);
            root.Append(new TaskFailureNode());

            Assert.That(() => root.Run(null), Throws.Nothing);
            Assert.That(root.Run(null), Is.EqualTo(NodeState.Failure));
        }
Пример #2
0
        public void Selector_Red()
        {
            var root    = new SelectorNode();
            var failure = new TaskFailureNode();

            root.Append(failure);
            root.Append(new TaskSuccessNode());

            Assert.That(() => root.Run(null), Throws.Nothing);
            Assert.That(root.Run(null), Is.Not.EqualTo(NodeState.Failure)); //ignore failures and return last success
            Assert.That(failure.executed, Is.EqualTo(true));
        }
Пример #3
0
        public void Selector_Green()
        {
            var root = new SelectorNode();

            root.Append(new TaskSuccessNode());
            var failure = new TaskFailureNode();

            root.Append(failure);

            Assert.That(() => root.Run(null), Throws.Nothing);
            Assert.That(root.Run(null), Is.EqualTo(NodeState.Success)); //first is success so I expect the first node returns true
            Assert.That(failure.executed, Is.EqualTo(false));
        }
Пример #4
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
        }
Пример #5
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
        }