Skip to content

Commit 57a9748

Browse files
committed
Added return failure and success decorators
1 parent 1fb0664 commit 57a9748

File tree

8 files changed

+114
-0
lines changed

8 files changed

+114
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Adnc.FluidBT.Decorators;
2+
using Adnc.FluidBT.Tasks;
3+
using NUnit.Framework;
4+
using Assert = UnityEngine.Assertions.Assert;
5+
6+
namespace Adnc.FluidBT.Testing {
7+
public class ReturnFailureTest {
8+
public class UpdateMethod {
9+
[Test]
10+
public void Returns_failure_on_child_failure () {
11+
var returnSuccess = new ReturnFailure {
12+
child = A.TaskStub().WithUpdateStatus(TaskStatus.Failure).Build()
13+
};
14+
15+
Assert.AreEqual(TaskStatus.Failure, returnSuccess.Update());
16+
}
17+
18+
[Test]
19+
public void Returns_failure_on_child_success () {
20+
var returnSuccess = new ReturnFailure {
21+
child = A.TaskStub().WithUpdateStatus(TaskStatus.Success).Build()
22+
};
23+
24+
Assert.AreEqual(TaskStatus.Failure, returnSuccess.Update());
25+
}
26+
27+
[Test]
28+
public void Returns_continue_on_child_continue () {
29+
var returnSuccess = new ReturnFailure {
30+
child = A.TaskStub().WithUpdateStatus(TaskStatus.Continue).Build()
31+
};
32+
33+
Assert.AreEqual(TaskStatus.Continue, returnSuccess.Update());
34+
}
35+
}
36+
}
37+
}

Assets/FluidBehaviorTree/Editor/Testing/Decorators/ReturnFailureTest.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Adnc.FluidBT.Decorators;
2+
using Adnc.FluidBT.Tasks;
3+
using NUnit.Framework;
4+
using Assert = UnityEngine.Assertions.Assert;
5+
6+
namespace Adnc.FluidBT.Testing {
7+
public class ReturnSuccessTest {
8+
public class UpdateMethod {
9+
[Test]
10+
public void Returns_success_on_child_failure () {
11+
var returnSuccess = new ReturnSuccess {
12+
child = A.TaskStub().WithUpdateStatus(TaskStatus.Failure).Build()
13+
};
14+
15+
Assert.AreEqual(TaskStatus.Success, returnSuccess.Update());
16+
}
17+
18+
[Test]
19+
public void Returns_success_on_child_success () {
20+
var returnSuccess = new ReturnSuccess {
21+
child = A.TaskStub().WithUpdateStatus(TaskStatus.Success).Build()
22+
};
23+
24+
Assert.AreEqual(TaskStatus.Success, returnSuccess.Update());
25+
}
26+
27+
[Test]
28+
public void Returns_continue_on_child_continue () {
29+
var returnSuccess = new ReturnSuccess {
30+
child = A.TaskStub().WithUpdateStatus(TaskStatus.Continue).Build()
31+
};
32+
33+
Assert.AreEqual(TaskStatus.Continue, returnSuccess.Update());
34+
}
35+
}
36+
}
37+
}

Assets/FluidBehaviorTree/Editor/Testing/Decorators/ReturnSuccessTest.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Adnc.FluidBT.Tasks;
2+
3+
namespace Adnc.FluidBT.Decorators {
4+
public class ReturnFailure : DecoratorBase {
5+
protected override TaskStatus OnUpdate () {
6+
var status = child.Update();
7+
if (status == TaskStatus.Continue) {
8+
return status;
9+
}
10+
11+
return TaskStatus.Failure;
12+
}
13+
}
14+
}

Assets/FluidBehaviorTree/Scripts/TaskParents/Decorators/ReturnFailure.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Adnc.FluidBT.Tasks;
2+
3+
namespace Adnc.FluidBT.Decorators {
4+
public class ReturnSuccess : DecoratorBase {
5+
protected override TaskStatus OnUpdate () {
6+
var status = child.Update();
7+
if (status == TaskStatus.Continue) {
8+
return status;
9+
}
10+
11+
return TaskStatus.Success;
12+
}
13+
}
14+
}

Assets/FluidBehaviorTree/Scripts/TaskParents/Decorators/ReturnSuccess.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)