本文整理汇总了Python中models.Node.add_transition方法的典型用法代码示例。如果您正苦于以下问题:Python Node.add_transition方法的具体用法?Python Node.add_transition怎么用?Python Node.add_transition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Node
的用法示例。
在下文中一共展示了Node.add_transition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_automata_without_final_states
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_automata_without_final_states(self):
initial = Node()
final = Node()
initial.add_transition('a', final)
automata = Automata([initial, final], ['a'], initial, [])
#assert para que haya alguno, la idea es que si no tendría que tirar excepción.
self.assertTrue(automata.initial == initial)
示例2: test_is_deterministic_automata__det
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_is_deterministic_automata__det(self):
initial = Node()
final = Node()
other_node = Node()
initial.add_transition('a', final)
automata = Automata([initial, final, other_node], ['a'], initial, [final])
self.assertTrue(automata.is_deterministic())
self.assertFalse(automata.has_lambda())
示例3: test_add_transition__new_symbol
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_add_transition__new_symbol(self):
tested = Node()
target = Node()
s = 'a'
self.assertFalse(s in tested.transitions)
tested.add_transition(s, target)
self.assertTrue(s in tested.transitions)
self.assertEqual([target], tested.transitions[s])
示例4: test_add_transition__existing_symbol
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_add_transition__existing_symbol(self):
tested = Node()
target1 = Node()
target2 = Node()
s = 'a'
tested.add_transition(s, target1)
tested.add_transition(s, target2)
self.assertEqual(set([target1, target2]), set(tested.transitions[s]))
示例5: test_is_deterministic_node__not_det
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_is_deterministic_node__not_det(self):
tested = Node()
target1 = Node()
target3 = Node()
s = 'a'
tested.add_transition(s, target1)
tested.add_transition(s, target3)
self.assertFalse(tested.is_deterministic())
示例6: test_is_deterministic_node__lambda_det
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_is_deterministic_node__lambda_det(self):
tested = Node()
target1 = Node()
target2 = Node()
s = 'a'
tested.add_transition(s, target1)
tested.add_transition(LAMBDA, target2)
self.assertFalse(tested.is_deterministic())
示例7: test_construction_automata__extra_final
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_construction_automata__extra_final(self):
initial = Node()
final = Node()
initial.add_transition('a', final)
states = [initial, final]
symbols = ['a']
with self.assertRaises(FinalsNotInStatesException):
Automata(states, symbols, initial, [final, Node()])
示例8: test_is_deterministic_node__det
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_is_deterministic_node__det(self):
tested = Node()
target1 = Node()
target2 = Node()
s = 'a'
s2 = 'b'
tested.add_transition(s, target1)
tested.add_transition(s2, target2)
self.assertTrue(tested.is_deterministic())
示例9: to_automata
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def to_automata(self):
content_automata = self.content.to_automata()
q0 = Node()
qf = Node()
states = [q0, qf] + content_automata.states
q0.add_transition(LAMBDA, qf)
q0.add_transition(LAMBDA, content_automata.initial)
for q in content_automata.finals:
q.add_transition(LAMBDA, qf)
return Automata(states, content_automata.symbols, q0, [qf])
示例10: test_reachable_nodes
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_reachable_nodes(self):
q0 = Node("q0")
q1 = Node("q1")
q2 = Node("q2")
q0.add_transition(0, q1)
q0.add_transition(1, q2)
q2.add_transition(1, q1)
self.assertEqual(set([q1, q2]), q0.reachable_nodes())
self.assertEqual(set([]), q1.reachable_nodes())
self.assertEqual(set([q1]), q2.reachable_nodes())
示例11: test_minimize__con_nodo_trampa
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_minimize__con_nodo_trampa(self):
q0 = Node('q0')
q1 = Node('q1')
qT = Node('qT')
q0.add_transition('0', q1)
q0.add_transition('0', qT)
q0.add_transition('1', qT)
q1.add_transition('0', qT)
q1.add_transition('0', qT)
qT.add_transition('0', qT)
qT.add_transition('1', qT)
automata = Automata([q0, q1, qT], ['0', '1'], q0, [q1])
minimized = minimize(automata)
self.assertEquals(set(minimized.symbols), set(automata.symbols))
self.assertEquals(len(minimized.states), 2)
q0 = minimized.state_by_name('q0')
q1 = minimized.state_by_name('q1')
self.assertEquals(q0.transition('0'), q1)
self.assertEquals(q0.transitions.keys(), ['0'])
self.assertEquals(q1.transitions.keys(), [])
示例12: test_interseccion_vacia
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_interseccion_vacia(self):
q0 = Node("q0")
q1 = Node("q1")
q0.add_transition('0', q1)
q0.add_transition('1', q0)
automata1 = Automata([q0, q1], ['0', '1'], q0, [q1])
q2 = Node("q2")
q3 = Node("q3")
q2.add_transition('1', q3)
q2.add_transition('0', q2)
automata2 = Automata([q2, q3], ['0', '1'], q2, [q3])
interseccion = afd_interseccion(automata1, automata2)
self.assertEqual(set(automata1.symbols), set(interseccion.symbols))
self.assertEqual(0, len(interseccion.states))
示例13: test_interseccion_dos_automatas_iguales
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_interseccion_dos_automatas_iguales(self):
q0 = Node("q0")
q1 = Node("q1")
q0.add_transition('0', q1)
q0.add_transition('1', q1)
q1.add_transition('0', q0)
automata = Automata([q0, q1], ['0', '1'], q0, [q1])
result = afd_interseccion(automata, automata)
self.assertEqual(set(automata.symbols), set(result.symbols))
self.assertEqual(len(automata.states), len(result.states))
self.assertEqual(len(automata.finals), len(result.finals))
qI = result.initial
qII = result.finals[0]
self.assertEqual(qII, qI.transition('0'))
self.assertEqual(qII, qI.transition('1'))
self.assertEqual(qI, qII.transition('0'))
示例14: test_no_determinismo
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_no_determinismo(self):
q0_1 = Node("q0")
q1_1 = Node("q1")
q0_1.add_transition('0', q1_1)
q0_1.add_transition('1', q1_1)
q1_1.add_transition('0', q0_1)
automata1 = Automata([q0_1, q1_1], ['0', '1'], q0_1, [q1_1])
q0_2 = Node("q0")
q1_2 = Node("q1")
q0_2.add_transition('0', q1_2)
q0_2.add_transition('1', q1_2)
q1_2.add_transition('0', q0_2)
q1_2.add_transition('0', q1_2)
q1_2.add_transition('1', q1_2)
automata2 = Automata([q0_2, q1_2], ['0', '1'], q0_2, [q1_2])
with self.assertRaises(NonDeterministicAutomataError):
afd_interseccion(automata1, automata2)
示例15: test_add_terminal_node__ejemplo_simple
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add_transition [as 别名]
def test_add_terminal_node__ejemplo_simple(self):
q0 = Node('q0')
q1 = Node('q1')
q2 = Node('q2')
q0.add_transition('a', q1)
q1.add_transition('b', q2)
q2.add_transition('a', q2)
q2.add_transition('b', q2)
symbols = ['a', 'b']
automata = Automata([q0, q1, q2], symbols, q0, [q2])
with_terminal_node = add_terminal_node(automata)
self.assertEqual(automata.symbols, with_terminal_node.symbols)
self.assertEqual(len(automata.states) + 1, len(with_terminal_node.states))
q0T = with_terminal_node.state_by_name("q0")
q1T = with_terminal_node.state_by_name("q1")
q2T = with_terminal_node.state_by_name("q2")
qT = with_terminal_node.state_by_name("qT")
self.assertEqual(symbols, q0T.transitions.keys())
self.assertEqual([q1T], q0T.transitions['a'])
self.assertEqual([qT], q0T.transitions['b'])
self.assertEqual(symbols, q1T.transitions.keys())
self.assertEqual([qT], q1T.transitions['a'])
self.assertEqual([q2T], q1T.transitions['b'])
self.assertEqual(symbols, q2T.transitions.keys())
self.assertEqual([q2T], q2T.transitions['a'])
self.assertEqual([q2T], q2T.transitions['b'])
self.assertEqual(symbols, qT.transitions.keys())
self.assertEqual([qT], qT.transitions['a'])
self.assertEqual([qT], qT.transitions['b'])