def test_sequence(Sample_Blackboard, test_stack, test_list_1, test_list_2, test_list_3): print('\n A sequence should end if one of the nodes fails') test_sequence_1 = sequence(test_list_1) test_sequence_2 = sequence(test_list_2) test_sequence_3 = sequence(test_list_3) print(' Testing sequence one') test_sequence_1.execute(Sample_Blackboard, test_stack) print(' Testing sequence two') test_sequence_2.execute(Sample_Blackboard, test_stack) print(' Testing sequence three') test_sequence_3.execute(Sample_Blackboard, test_stack)
def create_spot(): # Create all tasks related to spot cleaning Spot_condition = condition('SPOT') Clean_Spot = task('Clean Spot', None, None, None) Spot_Timer = timer(20, Clean_Spot) Done_Spot = task('Done Spot', 'write', 'SPOT', False) # Create list of tasks and create/return squence Spot_tasks_list = [Spot_condition, Spot_Timer, Done_Spot] return sequence(Spot_tasks_list)
def create_battery_branch(): #Creating all tasks related to going home Battery_condition = condition('BATTERY_UNDER_30') Find_home = task('Find Home', 'write', 'HOME_PATH', 'It is over there!') Go_home = task('Go Home', 'recive', 'HOME_PATH', None) Dock = task('Dock', 'write', 'SIM_OVER', True) # Create list of tasks and create/return squence Battery_Task_List = [Battery_condition, Find_home, Go_home, Dock] return sequence(Battery_Task_List)
def create_general(): # Create dusty spot cleaner Dusty_condition = condition('DUSTY_SPOT') Clean_Dusty = task('Clean Spot', None, None, None) Dusty_Timer = timer(35, Clean_Dusty) Dusty_Clean_Sequence = sequence([Dusty_condition, Dusty_Timer]) # Create branches that check battery and do a simlpe clean Clean = task('Clean', None, None, None) General_Selector = selector([Dusty_Clean_Sequence, Clean]) Battery_condition = condition('BATTERY_UNDER_30') Battery_Negation = negation(Battery_condition) Untill_False_Sequence = sequence([Battery_Negation, General_Selector]) Untill_False_Node = until_false(Untill_False_Sequence) # Create branches that check if the user wants to execute general then #create and return whole sequence Done_General = task('Done General', 'write', 'GENERAL', False) Execute_Sequence = sequence([Untill_False_Node, Done_General]) General_condition = condition('GENERAL') return sequence([General_condition, Execute_Sequence])
def test_priority(Sample_Blackboard, test_stack, test_node_1, test_node_2, Condition_1): Sample_Blackboard['EAT_PIZZA'] = False print('\n A Priority node should end the when one of its nodes' 'succeeds... and evaluated nodes in order regarless if one' 'is running ') Test_timer = timer(10, test_node_1) test_sequence_4 = sequence([Test_timer, test_node_2]) test_list_prioity = [Condition_1, test_sequence_4] test_priority = priority(test_list_prioity) priority_result = None x = 0 while priority_result != 'SUCCEEDED': priority_result = test_priority.execute(Sample_Blackboard, test_stack) x += 1 print('Priority is returning', priority_result, ' for cycle', x) print(' Priority Node was A Success ')
def test_Decorators(Sample_Blackboard): print('\n\n Finally we will test our Decorators types') test_node_1 = task('Enter Carm', None, None, None) test_node_3 = task('Eat Pizza', 'write', 'EAT_PIZZA', True) Condition_1 = condition('EAT_PIZZA') test_list_1 = [Condition_1, test_node_1] test_stack = [] print('\n Let us test our negations') Test_negation_1 = negation(Condition_1) Test_negation_2 = negation(test_node_3) if Test_negation_1.execute(Sample_Blackboard, test_stack) == 'SUCCEEDED': print(' Test_negation_1 returns SUCCEEDED, worked correctly') if Test_negation_2.execute(Sample_Blackboard, test_stack) == 'FAILED': print(' Test_negation_2 returns FAILED, worked correctly') if Test_negation_1.execute(Sample_Blackboard, test_stack) == 'FAILED': print(' Test_negation_1 returns FAILED now, worked correctly') print('\n Let us test a timer') Test_timer = timer(10, test_node_1) Test_timer.execute(Sample_Blackboard, test_stack) print(' Timer is at:', Sample_Blackboard['TIMER']) while Test_timer.execute(Sample_Blackboard, test_stack) == 'RUNNING': print(' Timer is at:', Sample_Blackboard['TIMER']) print('\n Let us test timer again, to make sure it works twice') Test_timer.execute(Sample_Blackboard, test_stack) print(' Timer is at:', Sample_Blackboard['TIMER']) while Test_timer.execute(Sample_Blackboard, test_stack) == 'RUNNING': print(' Timer is at:', Sample_Blackboard['TIMER']) Sample_Blackboard['EAT_PIZZA'] = True print('\n Let us test our until false, should run 8 times') test_sequence_1 = sequence(test_list_1) Test_until_false = until_false(test_sequence_1) for x in range(1, 20): if Test_until_false.execute(Sample_Blackboard, test_stack) == 'RUNNING': print(' This is the', x, 'time untill_false has run') if x == 8: Sample_Blackboard['EAT_PIZZA'] = False