Esempio n. 1
0
    def test_mwalker(self):
        """
        Test method walker
        """
        class MW(MWalker):
            def __init__(self):
                self.walked = []

            def visit(self, n):
                self.walked.append(n)

            v_diagram = v_packagingelement = v_element = visit


        mw = MW()

        n1 = Diagram()
        n1.id = 'n1'

        n2 = PackagingElement('a', id='n2')
        n3 = PackagingElement('a', id='n3')
        n4 = Element('a', id='n4')

        n1.children.extend((n2, n3))
        n2.children.append(n4)

        mw.preorder(n1)
        self.assertEquals([n1, n2, n4, n3], mw.walked)
Esempio n. 2
0
    def test_lca(self):
        """
        Test LCA
        """
        n1 = Diagram()
        n1.id = 'n1'

        n2 = Element('a', id='n2')
        n3 = Element('a', id='n3')
        n1.children.extend((n2, n3))
        n2.parent = n1
        n3.parent = n1

        p = lca(n1, n2, n3)
        self.assertEquals('n1', p.id)
Esempio n. 3
0
    def test_unwind(self):
        """
        Test unwind
        """
        n1 = Diagram()
        n1.id = 'n1'

        n2 = PackagingElement('a', id='n2')
        n3 = PackagingElement('a', id='n3')
        n4 = Element('a', id='n4')

        n1.children.extend((n2, n3))
        n2.children.append(n4)

        n2.parent = n1
        n3.parent = n1
        n4.parent = n2

        self.assertEquals([n1, n2, n4, n3], list(unwind(n1)))
Esempio n. 4
0
    def test_preorder(self):
        """
        Test preorder traversing
        """
        def f(n):
            f.t += 1
        f.t = 0

        n1 = Diagram()
        n1.id = 'n1'

        n2 = PackagingElement('a', id='n2')
        n3 = PackagingElement('a', id='n3')
        n4 = Element('a', id='n4')

        n1.children.extend((n2, n3))
        n2.children.append(n4)

        preorder(n1, f)
        self.assertEquals(4, f.t)
Esempio n. 5
0
    def test_lsb(self):
        """
        Test LSB
        """
        n1 = Diagram()
        n1.id = 'n1'

        n2 = PackagingElement('a', id='n2')
        n3 = PackagingElement('a', id='n3')
        n4 = PackagingElement('a', id='n4')

        n1.children.extend((n2, n3))
        n2.children.append(n4)

        n2.parent = n1
        n3.parent = n1
        n4.parent = n2

        siblings = lsb(n1, n3, n4)
        self.assertEquals([n3, n2], siblings)
Esempio n. 6
0
    def test_lca_order(self):
        """
        Test LCA ordering
        """
        n1 = Diagram()
        n1.id = 'd1'

        n2 = Element('a', id='n2')
        n3 = PackagingElement('a', id='dc2')
        n4 = Element('a', id='n4')
        n5 = Element('a', id='n5')
        n1.children.extend((n2, n3))
        n2.parent = n1
        n3.parent = n1

        n3.children.extend((n4, n5))
        n4.parent = n3
        n5.parent = n3

        p = lca(n1, n4, n5)
        self.assertEquals('dc2', p.id)