コード例 #1
0
        public void ShouldSucceed_WhenFirstChildSuccessful()
        {
            MockNode       firstChild   = new MockNode();
            MockNode       secondChild  = new MockNode();
            RandomSelector sut          = new RandomSelector(firstChild, secondChild);
            TestRoot       behaviorTree = CreateBehaviorTree(sut);

            behaviorTree.Start();

            MockNode firstActiveChild = sut.DebugGetActiveChild() as MockNode;
            MockNode inactiveChild    = firstActiveChild == firstChild ? secondChild : firstChild;

            Assert.IsNotNull(firstActiveChild);

            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, firstActiveChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, inactiveChild.CurrentState);

            firstActiveChild.Finish(true);

            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, secondChild.CurrentState);
            Assert.IsTrue(behaviorTree.DidFinish);
            Assert.IsTrue(behaviorTree.WasSuccess);
        }
コード例 #2
0
        public void StopLowerPriorityChildrenForChild_WithImmediateRestart_ShouldNotRestartFirstChild_WhenSecondChildSucceeds()
        {
            MockNode       firstChild   = new MockNode();
            MockNode       secondChild  = new MockNode(true);
            RandomSelector sut          = new RandomSelector(firstChild, secondChild);
            TestRoot       behaviorTree = CreateBehaviorTree(sut);

            // TODO: will we keep the priority or will we switch to the priority defined by the randomized children?
            RandomSelector.DebugSetSeed(2);

            behaviorTree.Start();
            firstChild.Finish(false);

            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.ACTIVE, secondChild.CurrentState);

            sut.StopLowerPriorityChildrenForChild(firstChild, true);

            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, firstChild.CurrentState);
            Assert.AreEqual(Node.State.INACTIVE, secondChild.CurrentState);
            Assert.IsTrue(behaviorTree.DidFinish);
            Assert.IsTrue(behaviorTree.WasSuccess);
        }
コード例 #3
0
        public void ShouldSucceed_WhenStoppedExplicitlyButChildStillFinishesSuccessfully()
        {
            MockNode       succeedingChild = new MockNode(true);
            RandomSelector sut             = new RandomSelector(succeedingChild);
            TestRoot       behaviorTree    = CreateBehaviorTree(sut);

            behaviorTree.Start();

            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);

            sut.Stop();

            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.IsTrue(behaviorTree.DidFinish);
            Assert.True(behaviorTree.WasSuccess);
        }
コード例 #4
0
        public void ShouldFail_WhenSingleChildFails()
        {
            MockNode       failingChild = new MockNode();
            RandomSelector sut          = new RandomSelector(failingChild);
            TestRoot       behaviorTree = CreateBehaviorTree(sut);

            behaviorTree.Start();

            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);

            failingChild.Finish(false);

            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);
            Assert.IsTrue(behaviorTree.DidFinish);
            Assert.IsFalse(behaviorTree.WasSuccess);
        }