Skip to content

Commit 8aee8a4

Browse files
committed
Added test to verify reset hooks fire correctly
1 parent f4daa54 commit 8aee8a4

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

Assets/FluidBehaviorTree/Scripts/TaskParents/Composites/Editor/CompositeBaseTest.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
using Adnc.FluidBT.TaskParents.Composites;
2-
using Adnc.FluidBT.TaskParents;
2+
using Adnc.FluidBT.Tasks;
33
using NSubstitute;
44
using NUnit.Framework;
5+
using UnityEngine;
6+
using Tree = Adnc.FluidBT.Trees.Tree;
57

68
namespace Adnc.FluidBT.Testing {
79
public class CompositeBaseTest {
810
private CompositeExample _composite;
911

1012
public class CompositeExample : CompositeBase {
13+
public TaskStatus status;
14+
1115
public void SetChildIndex (int index) {
1216
ChildIndex = index;
1317
}
18+
19+
protected override TaskStatus OnUpdate () {
20+
return status;
21+
}
1422
}
1523

1624
[SetUp]
@@ -48,6 +56,18 @@ public void Calls_end_on_current_child () {
4856
}
4957

5058
public class ResetMethod : CompositeBaseTest {
59+
private GameObject _go;
60+
61+
[SetUp]
62+
public void BeforEach () {
63+
_go = new GameObject();
64+
}
65+
66+
[TearDown]
67+
public void AfterEach () {
68+
Object.DestroyImmediate(_go);
69+
}
70+
5171
[Test]
5272
public void Resets_child_node_pointer () {
5373
_composite.SetChildIndex(2);
@@ -56,6 +76,34 @@ public void Resets_child_node_pointer () {
5676

5777
Assert.AreEqual(0, _composite.ChildIndex);
5878
}
79+
80+
[Test]
81+
public void Resets_pointer_if_tick_count_changes () {
82+
var tree = new Tree(_go);
83+
tree.AddNode(tree.Root, _composite);
84+
tree.AddNode(_composite, Substitute.For<ITask>());
85+
86+
tree.Tick();
87+
_composite.SetChildIndex(2);
88+
tree.Tick();
89+
90+
Assert.AreEqual(0, _composite.ChildIndex);
91+
}
92+
93+
[Test]
94+
public void Does_not_reset_pointer_if_tick_count_does_not_change () {
95+
var task = Substitute.For<ITask>();
96+
var tree = new Tree(_go);
97+
tree.AddNode(tree.Root, _composite);
98+
tree.AddNode(_composite, task);
99+
_composite.status = TaskStatus.Continue;
100+
101+
tree.Tick();
102+
_composite.SetChildIndex(1);
103+
tree.Tick();
104+
105+
Assert.AreEqual(1, _composite.ChildIndex);
106+
}
59107
}
60108
}
61109
}

Assets/FluidBehaviorTree/Scripts/Tasks/Editor/TaskTest.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Adnc.FluidBT.Tasks;
22
using Adnc.FluidBT.Tasks.Actions;
33
using NUnit.Framework;
4+
using UnityEngine;
5+
using Tree = Adnc.FluidBT.Trees.Tree;
46

57
namespace Adnc.FluidBT.Testing {
68
public class TaskTest {
@@ -35,6 +37,44 @@ public void SetUpNode () {
3537
node = new TaskExample();
3638
}
3739

40+
public class TreeTickCountChange : UpdateMethod {
41+
private GameObject _go;
42+
43+
[SetUp]
44+
public void BeforEach () {
45+
_go = new GameObject();
46+
}
47+
48+
[TearDown]
49+
public void AfterEach () {
50+
Object.DestroyImmediate(_go);
51+
}
52+
53+
[Test]
54+
public void Retriggers_start_if_tick_count_changes () {
55+
var tree = new Tree(_go);
56+
tree.AddNode(tree.Root, node);
57+
58+
tree.Tick();
59+
tree.Tick();
60+
61+
Assert.AreEqual(2, node.StartCount);
62+
}
63+
64+
[Test]
65+
public void Does_not_retrigger_start_if_tick_count_stays_the_same () {
66+
node.status = TaskStatus.Continue;
67+
68+
var tree = new Tree(_go);
69+
tree.AddNode(tree.Root, node);
70+
71+
tree.Tick();
72+
tree.Tick();
73+
74+
Assert.AreEqual(1, node.StartCount);
75+
}
76+
}
77+
3878
public class StartEvent : UpdateMethod {
3979
[Test]
4080
public void Trigger_on_1st_run () {

0 commit comments

Comments
 (0)