当前位置: 首页>>代码示例>>Python>>正文


Python Node.add_transition方法代码示例

本文整理汇总了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)
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:10,代码来源:test_models.py

示例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())
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:11,代码来源:test_models.py

示例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])
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:12,代码来源:test_models.py

示例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]))
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:12,代码来源:test_models.py

示例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())
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:12,代码来源:test_models.py

示例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())
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:12,代码来源:test_models.py

示例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()])
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:12,代码来源:test_models.py

示例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())
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:13,代码来源:test_models.py

示例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])
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:14,代码来源:parsers.py

示例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())
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:14,代码来源:test_models.py

示例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(), [])
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:27,代码来源:test_models.py

示例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))
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:21,代码来源:test_ejercicio_d.py

示例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'))
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:22,代码来源:test_ejercicio_d.py

示例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)
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:23,代码来源:test_ejercicio_d.py

示例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'])
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:37,代码来源:test_models.py


注:本文中的models.Node.add_transition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。