Skip to content

Commit

Permalink
Wait behaviour bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Milian Lichere committed Aug 7, 2018
1 parent 1d96c4e commit 99158bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/BehaviourTree.Tests/WaitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,25 @@ public void WhenWaitTimeExpires_ReturnSuccessAndResetTimer()

Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Running));
}

[Test]
public void WhenResetIsCalled_ReturnResetTimer()
{
var sut = new Wait<MockContext>(1000);
var context = new MockContext();

context.AddMilliseconds(500);

var behaviourStatus = sut.Tick(context);

Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Running));

sut.Reset();
context.AddMilliseconds(600);

behaviourStatus = sut.Tick(context);

Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Running));
}
}
}
5 changes: 5 additions & 0 deletions src/BehaviourTree/Behaviours/Wait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ protected override BehaviourStatus Update(TContext context)
}

protected override void OnTerminate(BehaviourStatus status)
{
DoReset(status);
}

protected override void DoReset(BehaviourStatus status)
{
_initialTimestamp = null;
}
Expand Down

0 comments on commit 99158bc

Please sign in to comment.