Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_count_leaf(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.LeafCount(), 5)