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)
Пример #2
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)
Пример #3
0
 def testInit(self):
     node = Node()
     self.assertIs(node.getParent(), None)
     self.assertIs(node.getRootNode(), node)
     self.assertEqual(len(node.getNormalChilds()), 0)
     self.assertEqual(len(node.getVirtualChilds()), 0)
     self.assertEqual(len(node.getAllChilds()), 0)
 def testInit(self):
     node = Node()
     self.assertIs(node.getParent(), None)
     self.assertIs(node.getRootNode(), node)
     self.assertEqual(len(node.getNormalChilds()), 0)
     self.assertEqual(len(node.getVirtualChilds()), 0)
     self.assertEqual(len(node.getAllChilds()), 0)
Пример #5
0
    def testInsert(self):
        node = Node()
        self.assertEqual(len(node.getNormalChilds()), 0)

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

        childNode2 = Node()
        node.insert(childNode2)
        self.assertIn(childNode1, childNode2.getNormalChilds())
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), childNode2)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)
        self.assertEqual(len(childNode1.getNormalChilds()), 0)
        self.assertEqual(len(childNode2.getNormalChilds()), 1)
    def testInsert(self):
        node = Node()
        self.assertEqual(len(node.getNormalChilds()), 0)

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

        childNode2 = Node()
        node.insert(childNode2)
        self.assertIn(childNode1, childNode2.getNormalChilds())
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), childNode2)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)
        self.assertEqual(len(childNode1.getNormalChilds()), 0)
        self.assertEqual(len(childNode2.getNormalChilds()), 1)
Пример #7
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)
Пример #8
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)
Пример #9
0
    def testRemove(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)

        node.remove(childNode1)
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), None)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)

        node.remove(childNode1)
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), None)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)

        with self.assertRaises(TypeError):
            node.remove([None])
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), None)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)

        with self.assertRaises(TypeError):
            node.remove([object])
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), None)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)

        with self.assertRaises(TypeError):
            node.remove(["a string is not a node object"])
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), None)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)
    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)
    def testRemove(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)

        node.remove(childNode1)
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), None)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)

        node.remove(childNode1)
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), None)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)

        with self.assertRaises(TypeError):
            node.remove([None])
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), None)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)

        with self.assertRaises(TypeError):
            node.remove([object])
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), None)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)

        with self.assertRaises(TypeError):
            node.remove(["a string is not a node object"])
        self.assertNotIn(childNode1, node.getNormalChilds())
        self.assertIn(childNode2, node.getNormalChilds())
        self.assertEqual(childNode1.getParent(), None)
        self.assertEqual(childNode2.getParent(), node)
        self.assertEqual(len(node.getNormalChilds()), 1)