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_repeat(self): target = [] tree = behaviours.repeat(behaviours.do("success", lambda state: state.append(True))) running, success = tree.tick(target) self.assertEqual(running, True) self.assertEqual(target, [True]) running, success = tree.tick(target) self.assertEqual(running, True) self.assertEqual(target, [True, True])
def test_repeat(self): target = [] tree = behaviours.repeat( behaviours.do("success", lambda state: state.append(True))) running, success = tree.tick(target) self.assertEqual(running, True) self.assertEqual(target, [True]) running, success = tree.tick(target) self.assertEqual(running, True) self.assertEqual(target, [True, True])