public void ShouldSucceed_WhenDecorated_Succeeded_GivenTimes() { MockNode succeedingChild = new MockNode(); var sut = new Loop(3).Decorate(succeedingChild); TestRoot behaviorTree = CreateBehaviorTree(sut); behaviorTree.Start(); Assert.AreEqual(Node.NodeStatus.Active, sut.CurrentStatus); for (int i = 0; i < 2; i++) { succeedingChild.Finish(true); Assert.AreEqual(Node.NodeStatus.Active, sut.CurrentStatus); Assert.IsFalse(behaviorTree.DidFinish); Timer.Tick(0.01f); } succeedingChild.Finish(true); Assert.AreEqual(Node.NodeStatus.Inactive, sut.CurrentStatus); Assert.IsTrue(behaviorTree.DidFinish); Assert.IsTrue(behaviorTree.WasSuccess); }
public void ShouldFail_When_Decorated_Fails() { MockNode failingChild = new MockNode(); var sut = new Loop().Decorate(failingChild); TestRoot behaviorTree = CreateBehaviorTree(sut); behaviorTree.Start(); Assert.AreEqual(Node.NodeStatus.Active, sut.CurrentStatus); failingChild.Finish(false); Assert.AreEqual(Node.NodeStatus.Inactive, sut.CurrentStatus); Assert.IsTrue(behaviorTree.DidFinish); Assert.IsFalse(behaviorTree.WasSuccess); }
public void Stopped_Immediate() { MockNode mainTask = new MockNode(); MockNode bgTree = new MockNode(); var sut = new SimpleParallel(SimpleParallel.FinishMode.IMMEDIATE).OpenBranch(mainTask, bgTree); var bt = CreateBehaviorTree(sut); bt.Start(); Assert.AreEqual(mainTask.CurrentStatus, Node.NodeStatus.Active); Assert.AreEqual(bgTree.CurrentStatus, Node.NodeStatus.Active); mainTask.Finish(true); Assert.AreEqual(mainTask.CurrentStatus, Node.NodeStatus.Inactive); Assert.AreEqual(bgTree.CurrentStatus, Node.NodeStatus.Inactive, "Immediate mode, bgTree should be stopped onced that mainTask complete"); Assert.AreEqual(sut.CurrentStatus, Node.NodeStatus.Inactive, "Immediate mode, simple parallel should be done"); }
public void ShouldFail_If_1st_Child_Fails() { var _1st = new MockNode(); var _2nd = new MockNode(); var _3rd = new MockNode(); var sut = new Sequence().OpenBranch(_1st, _2nd, _3rd); var bt = CreateBehaviorTree(sut); bt.Start(); _1st.Finish(false); Assert.AreEqual(_1st.CurrentStatus, Node.NodeStatus.Inactive); Assert.AreEqual(_2nd.CurrentStatus, Node.NodeStatus.Inactive); Assert.AreEqual(_3rd.CurrentStatus, Node.NodeStatus.Inactive); Assert.IsFalse(sut.debugLastResult); }
public void Cooldown_Test_Process_and_Reached() { for (int i = 0; i < 10; i++) { var rndTime = UnityEngine.Random.Range(0, 10f); MockNode child = new MockNode(); var sut = new Cooldown(rndTime).Decorate(child); var bt = CreateBehaviorTree(sut); bt.Start(); Assert.AreEqual(child.CurrentStatus, Node.NodeStatus.Active, "Cooldown, child should be ACTIVED"); child.Finish(true); //Timer.Tick(rndTime - UnityEngine.Random.Range(0, rndTime)); //Timer.Tick(rndTime); Assert.AreEqual(sut.CurrentStatus, Node.NodeStatus.Inactive); Assert.AreEqual(child.CurrentStatus, Node.NodeStatus.Inactive, "In Cooldown, child should not be ACTIVED"); } }
public void ShouldSuccess_When_All_Childs_Success() { var _1st = new MockNode(); var _2nd = new MockNode(); var _3rd = new MockNode(); var sut = new Sequence().OpenBranch(_1st, _2nd, _3rd); var bt = CreateBehaviorTree(sut); bt.Start(); _1st.Finish(true); _2nd.Finish(true); _3rd.Finish(true); Assert.AreEqual(_1st.CurrentStatus, Node.NodeStatus.Inactive); Assert.AreEqual(_2nd.CurrentStatus, Node.NodeStatus.Inactive); Assert.AreEqual(_3rd.CurrentStatus, Node.NodeStatus.Inactive); Assert.IsTrue(sut.debugLastResult); }
public void Stopped_Delayed() { MockNode mainTask = new MockNode(); MockNode bgTree = new MockNode(); var sut = new SimpleParallel(SimpleParallel.FinishMode.DELAYED).OpenBranch(mainTask, bgTree); var bt = CreateBehaviorTree(sut); bt.Start(); Assert.AreEqual(mainTask.CurrentStatus, Node.NodeStatus.Active); Assert.AreEqual(bgTree.CurrentStatus, Node.NodeStatus.Active); mainTask.Finish(true); Assert.AreEqual(mainTask.CurrentStatus, Node.NodeStatus.Inactive); Assert.AreEqual(bgTree.CurrentStatus, Node.NodeStatus.Active, "Delayed mode, bgTree could be permitted to finish onced that mainTask complete"); Assert.AreEqual(sut.CurrentStatus, Node.NodeStatus.Active, "Delayed mode, wait for bgTree"); bgTree.Finish(false); Assert.AreEqual(sut.CurrentStatus, Node.NodeStatus.Inactive, ""); }
public void Child_Return_First() { for (int i = 0; i < 10; i++) { var rndTime = UnityEngine.Random.Range(.01f, 10f); MockNode child = new MockNode(); var sut = new TimeLimit(rndTime).Decorate(child); var bt = CreateBehaviorTree(sut); bt.Start(); Assert.AreEqual(sut.CurrentStatus, Node.NodeStatus.Active, "TimeLimit AVTIVE"); Assert.AreEqual(child.CurrentStatus, Node.NodeStatus.Active, "Start, child should be ACTIVED"); Timer.Tick(rndTime * UnityEngine.Random.Range(0, .95f)); child.Finish(true); Assert.AreEqual(child.CurrentStatus, Node.NodeStatus.Inactive, "Child finished, child should be INACTIVED"); Assert.AreEqual(sut.debugLastResult, child.debugLastResult, "Return result should equal to child's result"); //bt.Cancel(); } }