Skip to content

Commit 99158bc

Browse files
author
Milian Lichere
committed
Wait behaviour bug fix
1 parent 1d96c4e commit 99158bc

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/BehaviourTree.Tests/WaitTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,25 @@ public void WhenWaitTimeExpires_ReturnSuccessAndResetTimer()
3535

3636
Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Running));
3737
}
38+
39+
[Test]
40+
public void WhenResetIsCalled_ReturnResetTimer()
41+
{
42+
var sut = new Wait<MockContext>(1000);
43+
var context = new MockContext();
44+
45+
context.AddMilliseconds(500);
46+
47+
var behaviourStatus = sut.Tick(context);
48+
49+
Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Running));
50+
51+
sut.Reset();
52+
context.AddMilliseconds(600);
53+
54+
behaviourStatus = sut.Tick(context);
55+
56+
Assert.That(behaviourStatus, Is.EqualTo(BehaviourStatus.Running));
57+
}
3858
}
3959
}

src/BehaviourTree/Behaviours/Wait.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ protected override BehaviourStatus Update(TContext context)
3737
}
3838

3939
protected override void OnTerminate(BehaviourStatus status)
40+
{
41+
DoReset(status);
42+
}
43+
44+
protected override void DoReset(BehaviourStatus status)
4045
{
4146
_initialTimestamp = null;
4247
}

0 commit comments

Comments
 (0)