Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #4
0
        public void SequenceFailCalled()
        {
            var sequence = new SequenceNode();
            var fail     = new TaskFailureNode();
            var success  = new TaskSuccessNode();

            sequence.Append(new TaskSuccessNode());
            sequence.Append(fail);
            sequence.Append(success);

            Assert.That(sequence.Run(null), Is.EqualTo(NodeState.Failure));
            Assert.That(fail.executed, Is.EqualTo(true));
            Assert.That(success.executed, Is.EqualTo(false));
        }
        public void WriteOnFailure_Green()
        {
            var root = new SequenceNode();
            var fail = new TaskFailureNode();

            fail.AppendDecorator(new SetValueOnFail("foo", () => 1));
            root.Append(fail);

            BT.BT bt = new BT.BT(root);
            bt.BlackBoard.SetValue("foo", 0);

            Assert.That(bt.BlackBoard.ReadValue <int>("foo"), Is.EqualTo(0));
            bt.Run();
            Assert.That(bt.BlackBoard.ReadValue <int>("foo"), Is.EqualTo(1));
        }
        public void ConditionSuccessSingle()
        {
            var root = new SequenceNode();
            var succ = new TaskSuccessNode();

            succ.AppendDecorator(new ConditionSuccess());
            root.Append(succ);

            var fail = new TaskFailureNode();

            fail.AppendDecorator(new ConditionFail());
            root.Append(fail);

            Assert.That(root.Run(null), Is.EqualTo(NodeState.Success));         //should skip the fail node
            Assert.That(succ.executed, Is.EqualTo(true));
            Assert.That(fail.executed, Is.EqualTo(false));
        }
Beispiel #7
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
        }
Beispiel #8
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
        }