Example #1
0
    def test_delete_node_subtree(self):
        root = SimpleTreeNode(0, None)
        tree = SimpleTree(root)

        node = SimpleTreeNode(1, None)
        node2 = SimpleTreeNode(2, None)
        node3 = SimpleTreeNode(3, None)
        node4 = SimpleTreeNode(1, None)
        node5 = SimpleTreeNode(5, None)
        node6 = SimpleTreeNode(1, None)

        tree.AddChild(root, node)
        tree.AddChild(root, node2)
        tree.AddChild(root, node3)
        tree.AddChild(node3, node4)
        tree.AddChild(node3, node5)
        tree.AddChild(node3, node6)

        self.assertEqual(tree.Count(), 7)

        tree.DeleteNode(node3)

        self.assertEqual(tree.Count(), 3)
        for item in [node3, node4, node5, node6]:
            self.assertNotIn(item, tree.GetAllNodes())
Example #2
0
    def test_move_node_with_subtree(self):
        root = SimpleTreeNode(0, None)
        tree = SimpleTree(root)

        node = SimpleTreeNode(1, None)
        node2 = SimpleTreeNode(2, None)
        node3 = SimpleTreeNode(3, None)
        node4 = SimpleTreeNode(1, None)
        node5 = SimpleTreeNode(5, None)
        node6 = SimpleTreeNode(1, None)

        tree.AddChild(root, node)
        tree.AddChild(root, node2)
        tree.AddChild(root, node3)
        tree.AddChild(node3, node4)
        tree.AddChild(node4, node5)
        tree.AddChild(node4, node6)

        self.assertEqual(tree.Count(), 7)
        self.assertEqual(tree.LeafCount(), 4)

        self.assertEqual(node4.Children, [node5, node6])
        self.assertEqual(node4.Parent, node3)

        tree.MoveNode(node4, node)

        self.assertEqual(tree.Count(), 7)
        self.assertEqual(tree.LeafCount(), 4)

        self.assertEqual(node4.Children, [node5, node6])
        self.assertEqual(node4.Parent, node)
Example #3
0
    def test_delete_node(self):
        root = SimpleTreeNode(0, None)
        tree = SimpleTree(root)

        node = SimpleTreeNode(1, None)
        node2 = SimpleTreeNode(2, None)

        tree.AddChild(root, node)
        tree.AddChild(root, node2)

        self.assertEqual(tree.Count(), 3)

        tree.DeleteNode(node)

        self.assertEqual(tree.Count(), 2)
        self.assertNotIn(node, tree.GetAllNodes())
Example #4
0
    def test_count_nodes(self):
        root = SimpleTreeNode(0, None)
        tree = SimpleTree(root)

        node = SimpleTreeNode(1, None)
        node2 = SimpleTreeNode(2, None)
        node3 = SimpleTreeNode(3, None)
        node4 = SimpleTreeNode(1, None)
        node5 = SimpleTreeNode(5, None)
        node6 = SimpleTreeNode(1, None)

        tree.AddChild(root, node)
        tree.AddChild(root, node2)
        tree.AddChild(root, node3)
        tree.AddChild(node3, node4)
        tree.AddChild(node3, node5)
        tree.AddChild(node3, node6)

        self.assertEqual(tree.Count(), 7)