Best Python code snippet using fMBT_python
triple_balancing_machine.py
Source:triple_balancing_machine.py
...10 if self._current_state == 'q0' and symbol_at_head == 'a':11 self._tape.set_value('A')12 self._tape.move_to_right()13 self._current_state = 'q1'14 self.set_transitions(key='q0->q1', value='a,A,R')15 elif self._current_state == 'q1' and symbol_at_head == 'a':16 self._tape.set_value('a')17 self._tape.move_to_right()18 self._current_state = 'q1'19 self.set_transitions(key='q1->q1', value='a,a,R')20 elif self._current_state == 'q1' and symbol_at_head == 'B':21 self._tape.set_value('B')22 self._tape.move_to_right()23 self._current_state = 'q1'24 self.set_transitions(key='q1->q1', value='B,B,R')25 elif self._current_state == 'q1' and symbol_at_head == 'b':26 self._tape.set_value('B')27 self._tape.move_to_right()28 self._current_state = 'q2'29 self.set_transitions(key='q1->q2', value='b,B,R')30 elif self._current_state == 'q2' and symbol_at_head == 'b':31 self._tape.set_value('b')32 self._tape.move_to_right()33 self._current_state = 'q2'34 self.set_transitions(key='q2->q2', value='b,b,R')35 elif self._current_state == 'q2' and symbol_at_head == 'C':36 self._tape.set_value('C')37 self._tape.move_to_right()38 self._current_state = 'q2'39 self.set_transitions(key='q2->q2', value='C,C,R')40 elif self._current_state == 'q2' and symbol_at_head == 'c':41 self._tape.set_value('C')42 self._tape.move_to_left()43 self._current_state = 'q3'44 self.set_transitions(key='q2->q3', value='c,C,L')45 elif self._current_state == 'q3' and symbol_at_head == 'b':46 self._tape.set_value('b')47 self._tape.move_to_left()48 self._current_state = 'q3'49 self.set_transitions(key='q3->q3', value='b,b,L')50 elif self._current_state == 'q3' and symbol_at_head == 'C':51 self._tape.set_value('C')52 self._tape.move_to_left()53 self._current_state = 'q3'54 self.set_transitions(key='q3->q3', value='C,C,L')55 elif self._current_state == 'q3' and symbol_at_head == 'B':56 self._tape.set_value('B')57 self._tape.move_to_left()58 self._current_state = 'q4'59 self.set_transitions(key='q3->q4', value='B,B,L')60 elif self._current_state == 'q4' and symbol_at_head == 'a':61 self._tape.set_value('a')62 self._tape.move_to_left()63 self._current_state = 'q4'64 self.set_transitions(key='q4->q4', value='a,a,L')65 elif self._current_state == 'q4' and symbol_at_head == 'B':66 self._tape.set_value('B')67 self._tape.move_to_left()68 self._current_state = 'q4'69 self.set_transitions(key='q4->q4', value='B,B,L')70 elif self._current_state == 'q4' and symbol_at_head == 'A':71 self._tape.set_value('A')72 self._tape.move_to_right()73 self._current_state = 'q0'74 self.set_transitions(key='q4->q0', value='A,A,R')75 elif self._current_state == 'q0' and symbol_at_head == 'B':76 self._tape.set_value('B')77 self._tape.move_to_right()78 self._current_state = 'q5'79 self.set_transitions(key='q0->q5', value='B,B,R')80 elif self._current_state == 'q5' and symbol_at_head == 'B':81 self._tape.set_value('B')82 self._tape.move_to_right()83 self._current_state = 'q5'84 self.set_transitions(key='q5->q5', value='B,B,R')85 elif self._current_state == 'q5' and symbol_at_head == 'C':86 self._tape.set_value('C')87 self._tape.move_to_right()88 self._current_state = 'q6'89 self.set_transitions(key='q5->q6', value='C,C,R')90 elif self._current_state == 'q6' and symbol_at_head == 'C':91 self._tape.set_value('C')92 self._tape.move_to_right()93 self._current_state = 'q6'94 self.set_transitions(key='q6->q6', value='C,C,R')95 elif (96 self._current_state == 'q6'97 and symbol_at_head == self._tape._blank_symbol98 ):99 self._tape.move_to_right()100 self._current_state = 'qf'101 self.set_transitions(key='q6->qf', value='#,#,R')102 else:103 self.set_transitions(key='fail', value='*,*,*')104 return {105 'tape': str(self._tape),106 'message': 'Ops... Is not a triple balancing.',107 'output': 'Rejected',108 'transitions': self._transitions,109 }110 return {111 'tape': str(self._tape),112 'message': 'Work done!',113 'output': 'Accepted',114 'transitions': self._transitions,...
Automata_OpenFst.py
Source:Automata_OpenFst.py
1import bisect2import matplotlib.pyplot as plt3import numpy as np4import pyparsing 5import graphviz 6import dot2tex7import openfst_python as fst 8def OpenFST_Automata_Example():9 f = fst.Fst()10 s0 = f.add_state()11 s1 = f.add_state()12 s2 = f.add_state()13 f.add_arc(s0, fst.Arc(1, 2, fst.Weight(f.weight_type(), 3.0), s1))14 f.add_arc(s0, fst.Arc(1, 3, fst.Weight.One(f.weight_type()), s2))15 f.add_arc(s1, fst.Arc(2, 1, fst.Weight(f.weight_type(), 1.0), s2))16 f.set_start(s0)17 f.set_final(s2, fst.Weight(f.weight_type(), 1.5))18 print(s0, s1, s2)19 print(f)20def Example_To_GraphViz():21 print("digraph G{")22 node0 = "0 [label = s0]"23 node1 = "1 [label = s1]"24 node2 = "2 [label = s2]"25 print(node0)26 print(node1)27 print(node2)28 edge_01 = "0 -> 1 [label=\"1:2 - 3.0\"]" 29 edge_02 = "0 -> 2 [label=\"1:3 - 2.0\"]"30 edge_12 = "1 -> 2 [label=\"2:1 - 1.0\"]"31 print(edge_01)32 print(edge_02)33 print(edge_12)34 print("}")35def OpenFST_Automata_Test(set_src_states, set_dst_states, set_labels):36 f = fst.Fst()37 for i, src in set_src_states:38 for j, label in set_labels[src]:39 for k, dst in set_dst_states[src][labels]:40 print(src, label, dst)41def printArcs(arcs):42 return str(arcs)43def printDsts(dsts):44 return(str(dsts))45def printTransitions(dico):46 print(dico["src"] + ' ' + printArcs(dico["arcs"]))# + ' ' + printDsts(dico["dsts"]))47def main():48 OpenFST_Automata_Example()49 Example_To_GraphViz()50 set_src_states = {51 "0": "s0",52 "1": "s1",53 "2": "s2"54 }55 print(set_src_states)56 set_labels = {57 "s0": ["1:1","epsilon"],58 "s1": ["1:2", "2:3"],59 "s2": ["2:2", "3:1"]60 }61 print(set_labels)62 set_dst_states = {63 "1:1": ["s1"],64 "1:2": ["s0"],65 "2:2": ["s0"],66 "2,3": ["s2"],67 "3:1": ["s0"],68 "epsilon": ["s2"]69 }70 print(set_dst_states)71 set_transitions = (72 {73 "src": "s0",74 "arcs": {75 {76 "arc_label": "1:1",77 "dsts": (78 "s0",79 "s1"80 )81 },82 {83 "arc_label": "epsilon",84 "dsts": (85 "s0",86 "s2"87 )88 }89 }90 },91 { 92 "src": "s1",93 "arcs": {94 {95 "arc_label": "1:2",96 "dsts": (97 "s0",98 "s2"99 )100 },101 {102 "arc_label": "2:3",103 "dsts": (104 "s1"105 )106 }107 108 }109 },110 {111 "src": "s2",112 "arcs": {113 {114 "arc_label": "2:2",115 "dsts": (116 "s2"117 )118 },119 {120 "arc_label": "1:3",121 "dsts": (122 "s0",123 "s1"124 )125 }126 }127 }128 )129 # print(set_transitions)130 # for transition in set_transitions:131 # for key_src, src in set_transitions[transition]:132 # for key_arc, arc in enumerate(set_transitions[transition]):133 # for key_dst, dst in enumerate(set_transitions[transition][arc]):134 # print(src, arc, dst)135 # map(printTransitions, set_transitions)136 137 138if __name__ == "__main__":139 # execute only if run as a script...
dungeon_alpha.py
Source:dungeon_alpha.py
...14 rect = Rect(7, 7, 11, 9)15 is_interior = True16 def __init__(self):17 super().__init__()18 self.set_transitions()19 def set_transitions(self):20 pass21class TownAlphaMayorHouse(PrefabStructure):22 _floors = mayor_house_floor_array()23 _blockers = mayor_house_blocker_array()24 _overhead = mayor_house_overhead_array()25 rect = Rect(43, 7, 14, 12)26 is_interior = True27 def __init(self):28 super().__init__()29 self.set_transitions()30 def set_transitions(self):31 pass32class TownAlphaGuardHut(PrefabStructure):33 _floors = guard_hut_floor_array()34 _blockers = guard_hut_blocker_array()35 _overhead = guard_hut_overhead_array()36 rect = Rect(14, 42, 7, 15)37 is_interior = True38 def __init(self):39 super().__init__()40 self.set_transitions()41 def set_transitions(self):42 pass43class TownAlphaChurch(PrefabStructure):44 _floors = church_floor_array()45 _blockers = church_blocker_array()46 _overhead = church_overhead_array()47 rect = Rect(84, 18, 7, 13)48 is_interior = True49 def __init(self):50 super().__init__()51 self.set_transitions()52 def set_transitions(self):53 pass54class TownAlphaOrphanage(PrefabStructure):55 _floors = orphanage_floor_array()56 _blockers = orphanage_blocker_array()57 _overhead = orphanage_overhead_array()58 rect = Rect(69, 14, 13, 10)59 is_interior = True60 def __init(self):61 super().__init__()62 self.set_transitions()63 def set_transitions(self):64 pass65class TownAlphaInn(PrefabStructure):66 _floors = inn_floor_array()67 _blockers = inn_blocker_array()68 _overhead = inn_overhead_array()69 rect = Rect(76, 42, 11, 10)70 is_interior = True71 def __init__(self):72 super().__init__()73 self.set_transitions()74 def set_transitions(self):75 pass76class TownAlphaTavern(PrefabStructure):77 _floors = tavern_floor_array()78 _blockers = tavern_blocker_array()79 _overhead = tavern_overhead_array()80 rect = Rect(72, 53, 17, 9)81 is_interior = True82 def __init(self):83 super().__init__()84 self.set_transitions()85 def set_transitions(self):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!