public void WhenThresholdIsAboveOne_ThrowException() { var child = new MockBehaviour { ReturnStatus = BehaviourStatus.Running }; Assert.Throws <ArgumentException>(() => { new Random <MockContext>(child, 1.1); }); }
public void ReturningReady_ShouldNotBeAllowed() { var sut = new MockBehaviour { ReturnStatus = BehaviourStatus.Ready }; Assert.Throws <InvalidOperationException>(() => sut.Tick(new MockContext())); }
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); }); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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); }
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); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); } }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); } }
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)); }
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)); }
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); }
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)); }