@@ -6,12 +6,12 @@ extends GdUnitTestSuite
66
77# TestSuite generated from
88const __source = "res://addons/beehave/nodes/decorators/delayer.gd"
9- const __action = "res://test/actions/count_up_action .gd"
9+ const __action = "res://test/actions/mock_action .gd"
1010const __tree = "res://addons/beehave/nodes/beehave_tree.gd"
1111const __blackboard = "res://addons/beehave/blackboard.gd"
1212
1313var tree : BeehaveTree
14- var action : ActionLeaf
14+ var action : MockAction
1515var delayer : DelayDecorator
1616var runner : GdUnitSceneRunner
1717
@@ -34,7 +34,7 @@ func before_test() -> void:
3434
3535func test_return_success_after_delay () -> void :
3636 delayer .wait_time = get_physics_process_delta_time ()
37- action .status = BeehaveNode .SUCCESS
37+ action .final_result = BeehaveNode .SUCCESS
3838 assert_that (tree .tick ()).is_equal (BeehaveNode .RUNNING )
3939 assert_that (tree .tick ()).is_equal (BeehaveNode .SUCCESS )
4040 # Assure that the delayer properly resets
@@ -44,16 +44,53 @@ func test_return_success_after_delay() -> void:
4444
4545func test_return_running_after_delay () -> void :
4646 delayer .wait_time = 1.0
47- action .status = BeehaveNode .RUNNING
47+ action .final_result = BeehaveNode .RUNNING
4848 assert_that (tree .tick ()).is_equal (BeehaveNode .RUNNING )
4949 await runner .simulate_frames (1 , 1000 )
5050 assert_that (tree .tick ()).is_equal (BeehaveNode .RUNNING )
51- action .status = BeehaveNode .SUCCESS
51+ action .final_result = BeehaveNode .SUCCESS
5252 assert_that (tree .tick ()).is_equal (BeehaveNode .SUCCESS )
5353 # Assure that the delayer properly resets
54- action .status = BeehaveNode .RUNNING
54+ action .final_result = BeehaveNode .RUNNING
5555 assert_that (tree .tick ()).is_equal (BeehaveNode .RUNNING )
5656 await runner .simulate_frames (1 , 1000 )
5757 assert_that (tree .tick ()).is_equal (BeehaveNode .RUNNING )
58- action .status = BeehaveNode .SUCCESS
58+ action .final_result = BeehaveNode .SUCCESS
5959 assert_that (tree .tick ()).is_equal (BeehaveNode .SUCCESS )
60+
61+ func test_after_run_called_on_success () -> void :
62+ delayer .wait_time = get_physics_process_delta_time ()
63+ action .final_result = BeehaveNode .SUCCESS
64+
65+ # First tick should be in delay
66+ assert_that (tree .tick ()).is_equal (BeehaveNode .RUNNING )
67+ assert_bool (action .after_run_called ).is_false ()
68+
69+ # Second tick should execute child and call after_run
70+ assert_that (tree .tick ()).is_equal (BeehaveNode .SUCCESS )
71+ assert_bool (action .after_run_called ).is_true ()
72+
73+ func test_after_run_called_on_failure () -> void :
74+ delayer .wait_time = get_physics_process_delta_time ()
75+ action .final_result = BeehaveNode .FAILURE
76+
77+ # First tick should be in delay
78+ assert_that (tree .tick ()).is_equal (BeehaveNode .RUNNING )
79+ assert_bool (action .after_run_called ).is_false ()
80+
81+ # Second tick should execute child and call after_run
82+ assert_that (tree .tick ()).is_equal (BeehaveNode .FAILURE )
83+ assert_bool (action .after_run_called ).is_true ()
84+
85+ func test_after_run_not_called_during_delay () -> void :
86+ delayer .wait_time = 1.0
87+ action .final_result = BeehaveNode .SUCCESS
88+
89+ # First tick should be in delay
90+ assert_that (tree .tick ()).is_equal (BeehaveNode .RUNNING )
91+ assert_bool (action .after_run_called ).is_false ()
92+
93+ # Wait a bit but not enough to complete delay
94+ await runner .simulate_frames (1 , 500 )
95+ assert_that (tree .tick ()).is_equal (BeehaveNode .RUNNING )
96+ assert_bool (action .after_run_called ).is_false ()
0 commit comments