예제 #1
0
        public void WhenThresholdIsAboveOne_ThrowException()
        {
            var child = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Running
            };

            Assert.Throws <ArgumentException>(() => { new Random <MockContext>(child, 1.1); });
        }
예제 #2
0
        public void ReturningReady_ShouldNotBeAllowed()
        {
            var sut = new MockBehaviour
            {
                ReturnStatus = BehaviourStatus.Ready
            };

            Assert.Throws <InvalidOperationException>(() => sut.Tick(new MockContext()));
        }
예제 #3
0
        public void WhenThresholdIsBelowOrEqualToZero_ThrowException()
        {
            var child = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Running
            };

            Assert.Throws <ArgumentException>(() => { new Random <MockContext>(child, 0); });
            Assert.Throws <ArgumentException>(() => { new Random <MockContext>(child, -10); });
        }
예제 #4
0
        public void WhenChildReturnSuccess_ReturnSuccess()
        {
            var child = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Succeeded
            };

            var sut = new UntilSuccess <MockContext>(child);

            var behaviourStatus = sut.Tick(new MockContext());

            Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Succeeded));
        }
예제 #5
0
        public void OnTick_ShouldReturnChildStatus(BehaviourStatus status)
        {
            var child = new MockBehaviour {
                ReturnStatus = status
            };

            var sut = new AutoReset <MockContext>(child);

            var behaviourStatus = sut.Tick(new MockContext());

            Assert.That(behaviourStatus, Is.EqualTo(status));
        }
예제 #6
0
        public void WhenChildTerminates_ResetChild(BehaviourStatus status)
        {
            var child = new MockBehaviour {
                ReturnStatus = status
            };

            var sut = new AutoReset <MockContext>(child);

            sut.Tick(new MockContext());

            Assert.That(child.ResetCount, Is.EqualTo(1));
        }
예제 #7
0
        public void WhileTimeLimitHasNotExpired_ReturnChildStatus(BehaviourStatus status)
        {
            var child = new MockBehaviour {
                ReturnStatus = status
            };
            var sut = new TimeLimit <MockContext>(child, 1000);

            var behaviourStatus = sut.Tick(new MockContext());

            Assert.That(behaviourStatus, Is.EqualTo(status));
            Assert.That(child.UpdateCallCount, Is.EqualTo(1));
        }
예제 #8
0
        public void WhenChildIsRunning_ContinueRunning()
        {
            var child = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Running
            };

            var sut = new AutoReset <MockContext>(child);

            sut.Tick(new MockContext());

            Assert.That(child.ResetCount, Is.EqualTo(0));
        }
예제 #9
0
        public void OnTerminate_ShouldNotBeCalledOnRunning()
        {
            var sut = new MockBehaviour
            {
                ReturnStatus = BehaviourStatus.Running
            };

            Assert.That(sut.TerminateCallCount, Is.EqualTo(0));

            sut.Tick(new MockContext());

            Assert.That(sut.TerminateCallCount, Is.EqualTo(0));
        }
예제 #10
0
        public void WhenReadyAndCallingReset_DoResetShouldNotBeCalled(BehaviourStatus status)
        {
            var sut = new MockBehaviour
            {
                ReturnStatus = status
            };

            Assert.That(sut.ResetCount, Is.EqualTo(0));

            sut.Reset();

            Assert.That(sut.ResetCount, Is.EqualTo(0));
        }
예제 #11
0
        public void WhenNotOnCooldownAndChildReturnRunning_ReturnRunningAndDoNotGoOnCooldown()
        {
            var child = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Running
            };
            var sut = new Cooldown <MockContext>(child, 1000);

            var behaviourStatus = sut.Tick(new MockContext());

            Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Running));
            Assert.That(child.TerminateCallCount, Is.EqualTo(0));
            Assert.That(sut.OnCooldown, Is.False);
        }
예제 #12
0
        public void WhenNotOnCooldownAndChildReturnSuccess_ReturnSuccessAndGoOnCooldown()
        {
            var child = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Succeeded
            };
            var sut = new Cooldown <MockContext>(child, 1000);

            var behaviourStatus = sut.Tick(new MockContext());

            Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Succeeded));
            Assert.That(child.TerminateCallCount, Is.EqualTo(1));
            Assert.That(sut.OnCooldown, Is.True);
        }
예제 #13
0
        public void WhenRandomValueIsBelowThreshold_DoNotCallChildAndReturnFailure()
        {
            var child = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Succeeded
            };
            var randomProvider = new MockRandomProvider();
            var sut            = new Random <MockContext>(child, 0.5, randomProvider);

            var behaviourStatus = sut.Tick(new MockContext());

            Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Failed));
            Assert.That(child.TerminateCallCount, Is.EqualTo(0));
        }
예제 #14
0
        public void OnTerminate_ShouldBeCalledOnSuccessOrFailure(BehaviourStatus status)
        {
            var sut = new MockBehaviour
            {
                ReturnStatus = status
            };

            Assert.That(sut.TerminateCallCount, Is.EqualTo(0));

            sut.Tick(new MockContext());

            Assert.That(sut.TerminateCallCount, Is.EqualTo(1));
            Assert.That(sut.TerminateStatus, Is.EqualTo(status));
        }
예제 #15
0
            public void WhenOneFailAndOtherIsStillRunning_ReturnRunning()
            {
                var first = new MockBehaviour {
                    ReturnStatus = BehaviourStatus.Running
                };
                var second = new MockBehaviour {
                    ReturnStatus = BehaviourStatus.Failed
                };

                var sut = new SimpleParallel <MockContext>(SimpleParallelPolicy.OnlyOneMustSucceed, first, second);

                var behaviourStatus = sut.Tick(new MockContext());

                Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Running));
            }
예제 #16
0
            public void WhenBothSucceed_ReturnSuccess()
            {
                var first = new MockBehaviour {
                    ReturnStatus = BehaviourStatus.Succeeded
                };
                var second = new MockBehaviour {
                    ReturnStatus = BehaviourStatus.Succeeded
                };

                var sut = new SimpleParallel <MockContext>(SimpleParallelPolicy.BothMustSucceed, first, second);

                var behaviourStatus = sut.Tick(new MockContext());

                Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Succeeded));
            }
예제 #17
0
        public void WhenReadyAndCallingReset_DoResetShouldNotBeCalledOnChild(BehaviourStatus status)
        {
            var childBehaviour = new MockBehaviour
            {
                ReturnStatus = status
            };

            var sut = new MockDecoratorBehaviour(childBehaviour);

            Assert.That(childBehaviour.ResetCount, Is.EqualTo(0));

            sut.Reset();

            Assert.That(childBehaviour.ResetCount, Is.EqualTo(0));
        }
예제 #18
0
        public void WhenRandomValueIsEqualToThreshold_CallChildAndReturnChildStatus(BehaviourStatus childStatus)
        {
            var child = new MockBehaviour {
                ReturnStatus = childStatus
            };
            var randomProvider = new MockRandomProvider();
            var sut            = new Random <MockContext>(child, 0.4, randomProvider);

            randomProvider.SetNextRandomDouble(0.4);

            var behaviourStatus = sut.Tick(new MockContext());

            Assert.That(behaviourStatus, Is.EqualTo(childStatus));
            Assert.That(child.TerminateCallCount, Is.EqualTo(1));
        }
예제 #19
0
        public void WhenChildReturnRunning_ReturnRunning()
        {
            var child = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Running
            };

            var sut = new UntilSuccess <MockContext>(child);

            for (var i = 0; i < 10; i++)
            {
                var behaviourStatus = sut.Tick(new MockContext());

                Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Running));
                Assert.That(child.TerminateCallCount, Is.EqualTo(0));
            }
        }
예제 #20
0
        public void WhenNotReadyAndCallingReset_DoResetShouldBeCalled(BehaviourStatus status)
        {
            var sut = new MockBehaviour
            {
                ReturnStatus = status
            };

            Assert.That(sut.ResetCount, Is.EqualTo(0));

            sut.Tick(new MockContext());

            sut.Reset();

            Assert.That(sut.ResetCount, Is.EqualTo(1));
            Assert.That(sut.ResetStatus, Is.EqualTo(status));
        }
예제 #21
0
            public void WhenTickedAndSomeChildrenAreStillRunning_CompletedChildrenShouldNotBeTicked()
            {
                var first = new MockBehaviour {
                    ReturnStatus = BehaviourStatus.Succeeded
                };
                var second = new MockBehaviour {
                    ReturnStatus = BehaviourStatus.Running
                };

                var sut = new SimpleParallel <MockContext>(SimpleParallelPolicy.BothMustSucceed, first, second);

                sut.Tick(new MockContext());
                sut.Tick(new MockContext());

                Assert.That(first.UpdateCallCount, Is.EqualTo(1));
                Assert.That(second.UpdateCallCount, Is.EqualTo(2));
            }
예제 #22
0
            public void WheOneFails_ReturnFailureAndReset()
            {
                var first = new MockBehaviour {
                    ReturnStatus = BehaviourStatus.Failed
                };
                var second = new MockBehaviour {
                    ReturnStatus = BehaviourStatus.Succeeded
                };

                var sut = new SimpleParallel <MockContext>(SimpleParallelPolicy.BothMustSucceed, first, second);

                var behaviourStatus = sut.Tick(new MockContext());

                Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Failed));
                Assert.That(first.ResetCount, Is.EqualTo(1));
                Assert.That(second.ResetCount, Is.EqualTo(1));
            }
예제 #23
0
        public void WhenTickedAndInACompletedStatus_ChildrenShouldAllBeTicked(SimpleParallelPolicy policy)
        {
            var first = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Succeeded
            };
            var second = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Succeeded
            };

            var sut = new SimpleParallel <MockContext>(policy, first, second);

            sut.Tick(new MockContext());
            sut.Tick(new MockContext());

            Assert.That(first.UpdateCallCount, Is.EqualTo(2));
            Assert.That(second.UpdateCallCount, Is.EqualTo(2));
        }
예제 #24
0
        public void OnInitialize_ShouldOnlyBeCalledTheFirstTime(BehaviourStatus status)
        {
            var sut = new MockBehaviour
            {
                ReturnStatus = status
            };

            Assert.That(sut.InitializeCallCount, Is.EqualTo(0));

            sut.Tick(new MockContext());

            Assert.That(sut.InitializeCallCount, Is.EqualTo(1));

            sut.Tick(new MockContext());

            Assert.That(sut.InitializeCallCount, Is.EqualTo(1));
        }
예제 #25
0
        public void WhenResettingWhileRunning_ReInitializeCounter()
        {
            var child = new MockBehaviour
            {
                ReturnStatus = BehaviourStatus.Running
            };

            var sut = new Repeat <MockContext>(child, 15);

            sut.Tick(new MockContext());
            sut.Tick(new MockContext());
            sut.Tick(new MockContext());

            sut.Reset();

            Assert.That(sut.Counter, Is.EqualTo(0));
        }
예제 #26
0
        public void WhileRepeatCountNotReached_ReturnRunning()
        {
            var child = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Succeeded
            };

            var sut = new Repeat <MockContext>(child, 10);

            for (var i = 0; i < 9; i++)
            {
                var behaviourStatus = sut.Tick(new MockContext());

                Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Running));
                Assert.That(sut.Counter, Is.EqualTo(i + 1));
                Assert.That(child.TerminateCallCount, Is.EqualTo(i + 1));
            }
        }
예제 #27
0
            public void WhenOneSucceed_ReturnSuccessAndReset()
            {
                var first = new MockBehaviour {
                    ReturnStatus = BehaviourStatus.Succeeded
                };
                var second = new MockBehaviour {
                    ReturnStatus = BehaviourStatus.Running
                };

                var sut = new SimpleParallel <MockContext>(SimpleParallelPolicy.OnlyOneMustSucceed, first, second);

                var behaviourStatus = sut.Tick(new MockContext());

                Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Succeeded));
                Assert.That(first.ResetCount, Is.EqualTo(1));
                Assert.That(second.ResetCount, Is.EqualTo(1));
            }
예제 #28
0
        public void WhenChildReturnFailure_ReturnFailureAndResetCounter()
        {
            var child = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Succeeded
            };

            var sut = new Repeat <MockContext>(child, 10);

            sut.Tick(new MockContext());

            child.ReturnStatus = BehaviourStatus.Failed;

            var behaviourStatus = sut.Tick(new MockContext());

            Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Failed));
            Assert.That(sut.Counter, Is.EqualTo(0));
        }
예제 #29
0
        public void WhenCooldownExpires_GoBackToRegularBehaviour()
        {
            var child = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Succeeded
            };
            var sut     = new Cooldown <MockContext>(child, 1000);
            var context = new MockContext();

            sut.Tick(context);

            context.AddMilliseconds(2000);

            var behaviourStatus = sut.Tick(context);

            Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Succeeded));
            Assert.That(child.TerminateCallCount, Is.EqualTo(2));
            Assert.That(sut.OnCooldown, Is.True);
        }
예제 #30
0
        public void WhenFirstTicked_ChildrenShouldAllBeStarted(SimpleParallelPolicy policy)
        {
            var first = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Running
            };
            var second = new MockBehaviour {
                ReturnStatus = BehaviourStatus.Running
            };

            var sut = new SimpleParallel <MockContext>(policy, first, second);

            sut.Tick(new MockContext());

            Assert.That(first.InitializeCallCount, Is.EqualTo(1));
            Assert.That(second.InitializeCallCount, Is.EqualTo(1));
            Assert.That(first.UpdateCallCount, Is.EqualTo(1));
            Assert.That(second.UpdateCallCount, Is.EqualTo(1));
        }