def test_conditional_long(self): state = dict(target=[], condition=True) tree = behaviours.conditional("condition", condition=behaviours.evalb("check", lambda state: state['condition']), true=behaviours.repeat(behaviours.do("success", lambda state: state['target'].append(True))), false=behaviours.repeat(behaviours.do("fail", lambda state: state['target'].append(False))), ) running, success = tree.tick(state) self.assertEqual(running, True) self.assertEqual(state['target'], [True]) running, success = tree.tick(state) self.assertEqual(running, True) self.assertEqual(state['target'], [True, True]) state['condition'] = False running, success = tree.tick(state) self.assertEqual(running, True) self.assertEqual(state['target'], [True, True, False]) state['condition'] = True running, success = tree.tick(state) self.assertEqual(running, True) self.assertEqual(state['target'], [True, True, False, True])
def test_conditional_long(self): state = dict(target=[], condition=True) tree = behaviours.conditional( "condition", condition=behaviours.evalb("check", lambda state: state['condition']), true=behaviours.repeat( behaviours.do("success", lambda state: state['target'].append(True))), false=behaviours.repeat( behaviours.do("fail", lambda state: state['target'].append(False))), ) running, success = tree.tick(state) self.assertEqual(running, True) self.assertEqual(state['target'], [True]) running, success = tree.tick(state) self.assertEqual(running, True) self.assertEqual(state['target'], [True, True]) state['condition'] = False running, success = tree.tick(state) self.assertEqual(running, True) self.assertEqual(state['target'], [True, True, False]) state['condition'] = True running, success = tree.tick(state) self.assertEqual(running, True) self.assertEqual(state['target'], [True, True, False, True])
def test_conditional(self): tree = behaviours.conditional("condition", condition=behaviours.evalb("check", lambda state: True), true=behaviours.do("exito", lambda state: state.append(True)), false=behaviours.do("fail", lambda state: state.append(False)), ) target = [] running, success = tree.tick(target) self.assertEqual(running, False) self.assertEqual(success, True) self.assertEqual(target, [True])
def test_conditional(self): tree = behaviours.conditional( "condition", condition=behaviours.evalb("check", lambda state: True), true=behaviours.do("exito", lambda state: state.append(True)), false=behaviours.do("fail", lambda state: state.append(False)), ) target = [] running, success = tree.tick(target) self.assertEqual(running, False) self.assertEqual(success, True) self.assertEqual(target, [True])