Пример #1
0
    def testInsertWithManyChilds(self):
        node = Node()
        self.assertEqual(len(node.getNormalChilds()), 0)

        for i in range(0, 200):
            node.append(Node())

        insertNode = Node()
        self.assertEqual(len(node.getNormalChilds()), 200)
        self.assertEqual(len(insertNode.getNormalChilds()), 0)
        node.insert(insertNode)
        self.assertEqual(len(node.getNormalChilds()), 1)
        self.assertEqual(len(insertNode.getNormalChilds()), 200)
    def testInsertWithManyChilds(self):
        node = Node()
        self.assertEqual(len(node.getNormalChilds()), 0)

        for i in range(0, 200):
            node.append(Node())

        insertNode = Node()
        self.assertEqual(len(node.getNormalChilds()), 200)
        self.assertEqual(len(insertNode.getNormalChilds()), 0)
        node.insert(insertNode)
        self.assertEqual(len(node.getNormalChilds()), 1)
        self.assertEqual(len(insertNode.getNormalChilds()), 200)
Пример #3
0
    def testExtend(self):
        node = Node()
        self.assertEqual(len(node.getNormalChilds()), 0)

        childNode1 = Node()
        childNode2 = Node()
        node.extend([childNode1, childNode2])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        childNode3 = Node()
        node.extend([childNode3])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        node.extend([])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        with self.assertRaises(TypeError):
            node.extend([None])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        with self.assertRaises(TypeError):
            node.append([object])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        with self.assertRaises(TypeError):
            node.append(["a string is not a node object"])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        with self.assertRaises(MultipleParentsError):
            node.extend([childNode1])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        childNode4 = Node()
        childNode5 = Node()
        with self.assertRaises(MultipleParentsError):
            node.extend([childNode4, childNode5, childNode5])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(childNode4.getParent(), None)
        self.assertEqual(childNode5.getParent(), None)
        self.assertEqual(len(node.getNormalChilds()), 3)
Пример #4
0
    def testAppend(self):
        node = Node()
        self.assertEqual(len(node.getNormalChilds()), 0)

        childNode1 = Node()
        node.append(childNode1)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)

        childNode2 = Node()
        node.append(childNode2)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        with self.assertRaises(TypeError):
            node.append(None)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        with self.assertRaises(TypeError):
            node.append(object)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        with self.assertRaises(TypeError):
            node.append("a string is not a node object")
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        with self.assertRaises(MultipleParentsError):
            node.append(childNode1)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        childNode3 = TestChildNode()
        node.append(childNode3)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)
    def testExtend(self):
        node = Node()
        self.assertEqual(len(node.getNormalChilds()), 0)

        childNode1 = Node()
        childNode2 = Node()
        node.extend([childNode1, childNode2])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        childNode3 = Node()
        node.extend([childNode3])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        node.extend([])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        with self.assertRaises(TypeError):
            node.extend([None])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        with self.assertRaises(TypeError):
            node.append([object])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        with self.assertRaises(TypeError):
            node.append(["a string is not a node object"])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        with self.assertRaises(MultipleParentsError):
            node.extend([childNode1])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)

        childNode4 = Node()
        childNode5 = Node()
        with self.assertRaises(MultipleParentsError):
            node.extend([childNode4, childNode5, childNode5])
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(childNode4.getParent(), None)
        self.assertEqual(childNode5.getParent(), None)
        self.assertEqual(len(node.getNormalChilds()), 3)
    def testAppend(self):
        node = Node()
        self.assertEqual(len(node.getNormalChilds()), 0)

        childNode1 = Node()
        node.append(childNode1)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)

        childNode2 = Node()
        node.append(childNode2)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        with self.assertRaises(TypeError):
            node.append(None)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        with self.assertRaises(TypeError):
            node.append(object)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        with self.assertRaises(TypeError):
            node.append("a string is not a node object")
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        with self.assertRaises(MultipleParentsError):
            node.append(childNode1)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 2)

        childNode3 = TestChildNode()
        node.append(childNode3)
        self.assertIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertIn(childNode3, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), node)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(childNode3.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 3)