Esempio n. 1
0
    def test_insertSingleChildElement(self):
        testTree = MultiParentTree()
        testTree.insertElement(1, "Foo")
        testTree.insertElement(2, "Bar")
        testTree.setRelationship(1, 2)  # Bar shall be a child of Foo

        rootElements = testTree.getRootElements()
        assert len(rootElements) == 1
        assert rootElements[0].data == "Foo"
        assert len(rootElements[0].childs) == 1
        assert rootElements[0].childs[0].data == "Bar"
        assert len(rootElements[0].childs[0].parents) == 1
        assert rootElements[0].childs[0].parents[0].data == "Foo"

        assert testTree.hasID(1) is True
        assert testTree.hasID(2) is True
        assert testTree.hasID(3) is False
Esempio n. 2
0
    def test_insertMultipleChildElement(self):
        testTree = MultiParentTree()
        testTree.insertElement(1, "Foo")
        testTree.insertElement(2, "Bar")
        testTree.insertElement(3, "42")
        testTree.setRelationship(1, 2)  # Bar shall be a child of Foo
        testTree.setRelationship(1, 3)  # 42 shall be a child of Foo

        assert testTree.setRelationship(1, 100) is False  # Test if the childID does not exist
        assert testTree.setRelationship(100, 1) is False  # Test if the parrentID does not exist

        rootElements = testTree.getRootElements()
        assert len(rootElements) == 1
        assert rootElements[0].data == "Foo"
        assert len(rootElements[0].childs) == 2

        assert testTree.getElementByID(1).getChildIDs() == [2, 3]

        assert testTree.getElementByID(100) is None

        assert testTree.getElementByID(1).hasParents() is False
        assert testTree.getElementByID(2).hasParents() is True

        assert rootElements[0].hasChilds() is True
        assert rootElements[0].childs[0].data == "Bar"
        assert rootElements[0].childs[1].data == "42"

        assert rootElements[0].getChildDict() == {2: 'Bar', 3: '42'}

        assert len(rootElements[0].childs[0].parents) == 1
        assert rootElements[0].childs[0].getParentIDs() == [1]
        assert rootElements[0].childs[0].getParentDict() == {1: "Foo"}
        assert rootElements[0].childs[0].hasChilds() is False
        assert rootElements[0].childs[0].parents[0].data == "Foo"
        assert len(rootElements[0].childs[1].parents) == 1
        assert rootElements[0].childs[1].parents[0].data == "Foo"
        assert rootElements[0].childs[1].hasChilds() is False