Skip to content

Commit

Permalink
[sequences] bugfix current child setting whilst moving through childr…
Browse files Browse the repository at this point in the history
…en (#304)
  • Loading branch information
sinback authored Nov 6, 2020
1 parent e7321a1 commit 88cb91d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions py_trees/composites.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def tick(self):
try:
# advance if there is 'next' sibling
self.current_child = self.children[index + 1]
index += 1
except IndexError:
pass

Expand Down
46 changes: 46 additions & 0 deletions tests/test_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,52 @@ def assert_details(text, expected, result):
##############################################################################


def test_static_sequence_successes():
console.banner('Static Sequence Successes')
assert_banner()

success1 = py_trees.behaviours.Success(name="Success1")
success2 = py_trees.behaviours.Success(name="Success2")
success3 = py_trees.behaviours.Success(name="Success3")
success4 = py_trees.behaviours.Success(name="Success4")

children = [
success1,
success2,
success3,
success4,
]
root = py_trees.composites.Sequence(name="Sequence", children=children)

root.tick_once()

assert_details("Current Child", success4.name, root.current_child.name)
assert root.tip().name == success4.name, 'should execute all 4 nodes of this Sequence'


def test_static_sequence_with_failure():
console.banner('Static Sequence With Failure')
assert_banner()

success1 = py_trees.behaviours.Success(name="Success1")
success2 = py_trees.behaviours.Success(name="Success2")
failure = py_trees.behaviours.Failure(name="Failure")
success3 = py_trees.behaviours.Success(name="Success3")

children = [
success1,
success2,
failure,
success3,
]
root = py_trees.composites.Sequence(name="Sequence", children=children)

root.tick_once()

assert_details("Current Child", failure.name, root.current_child.name)
assert root.tip().name == failure.name, 'should execute first 2 nodes of this Sequence and fail'


def test_tick_add_with_current_child():
console.banner('Tick-Add with Current Child')
assert_banner()
Expand Down

0 comments on commit 88cb91d

Please sign in to comment.