Ejemplo n.º 1
0
        public void Selector_Node_Stays_Running_When_A_Child_Is_Running()
        {
            var mock = Substitute.For <BTNode>();

            mock.Update().Returns(NodeState.Running);

            SelectorNode seq = new SelectorNode();

            seq.AddChild(mock);

            Assert.IsTrue(seq.Update() == NodeState.Running);
        }
Ejemplo n.º 2
0
        public void Selector_Node_Fails_If_All_Of_Its_Children_Fails(int childsCount)
        {
            SelectorNode seq = new SelectorNode();

            for (int i = 0; i < childsCount; i++)
            {
                var mock = Substitute.For <BTNode>();
                mock.Update().Returns(NodeState.Failure);
                seq.AddChild(mock);
            }

            for (int i = 0; i < childsCount; i++)
            {
                if (i == childsCount - 1)
                {
                    Assert.IsTrue(seq.Update() == NodeState.Failure);
                }
                else
                {
                    Assert.IsTrue(seq.Update() == NodeState.Running);
                }
            }
        }
Ejemplo n.º 3
0
        public void Sequence_Node_Succeds_When_One_Child_Succeeds(int childsCount, int successAt)
        {
            SelectorNode seq = new SelectorNode();

            for (int i = 0; i < childsCount; i++)
            {
                var mock = Substitute.For <BTNode>();
                mock.Update().Returns(i == successAt ? NodeState.Success : NodeState.Failure);
                seq.AddChild(mock);
            }

            for (int i = 0; i <= successAt; i++)
            {
                if (i == successAt)
                {
                    Assert.IsTrue(seq.Update() == NodeState.Success);
                }
                else
                {
                    Assert.IsTrue(seq.Update() == NodeState.Running);
                }
            }
        }
Ejemplo n.º 4
0
        public void Selector_Properly_Resets_After_Finishing(NodeState finishState)
        {
            SelectorNode seq       = new SelectorNode();
            int          finishIdx = finishState == NodeState.Failure ? 2 : 1;

            for (int i = 0; i < 3; i++)
            {
                var mock = Substitute.For <BTNode>();
                mock.Update().Returns(i == finishIdx ? finishState : NodeState.Failure);
                seq.AddChild(mock);
            }

            // if it runs correctly after the second time, it has been properly reset
            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i <= finishIdx; i++)
                {
                    var expected = i == finishIdx ? finishState : NodeState.Running;
                    Assert.IsTrue(seq.Update() == expected);
                }
            }
        }
Ejemplo n.º 5
0
        public void Selector_Succeeds_If_It_Has_No_Children()
        {
            SelectorNode seq = new SelectorNode();

            Assert.IsTrue(seq.Update() == NodeState.Success);
        }