示例#1
0
        public void ShouldSucceedButSetCooldownAfterDecorator_WhenDecorateeSucceeds_DueToParameter()
        {
            MockNode child        = new MockNode();
            Cooldown sut          = new Cooldown(1, true, false, false, child);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

            // start
            behaviorTree.Start();
            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);

            // wait 1.5 seconds
            behaviorTree.Clock.Update(1.5f);

            // make child suceed
            child.Finish(true);

            // ensure we're stopped
            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);

            // start again
            behaviorTree.Start();
            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);

            // ensure the child has not been started ( due to cooldown )
            Assert.AreEqual(Node.State.INACTIVE, child.CurrentState);

            // advance clock to be at 2.0 seconds
            behaviorTree.Clock.Update(0.5f);

            // ensure the child has not been started ( due to cooldown )
            Assert.AreEqual(Node.State.INACTIVE, child.CurrentState);

            // advance clock to be at 3 seconds
            behaviorTree.Clock.Update(1.0f);

            // ensure the child has been started
            Assert.AreEqual(Node.State.ACTIVE, child.CurrentState);
        }
示例#2
0
        public void ShouldFailAndNotSetCooldown_WhenDecorateeFails_DueToParameter()
        {
            MockNode failingChild = new MockNode();
            Cooldown sut          = new Cooldown(1, false, true, failingChild);
            TestRoot behaviorTree = CreateBehaviorTree(sut);

            // start
            behaviorTree.Start();
            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);

            // make child fail
            failingChild.Finish(false);

            // ensure we're stopped
            Assert.AreEqual(Node.State.INACTIVE, sut.CurrentState);

            // start again
            behaviorTree.Start();
            Assert.AreEqual(Node.State.ACTIVE, sut.CurrentState);

            // ensure the child has been started again ( due to cooldown not active )
            Assert.AreEqual(Node.State.ACTIVE, failingChild.CurrentState);
        }