コード例 #1
0
    def test_from_array_representation(self):
        bst = BinarySearchTree.from_array_representation([])
        self.assertEqual(bst, self.empty_bst)

        array = binarytree.bst(height=random.randint(0, 9),
                               is_perfect=random.choice([True, False])).values
        bst = BinarySearchTree.from_array_representation(array)
        self.assertEqual(array, bst.to_array_representation())
コード例 #2
0
    def setUp(self):
        self.empty_bst = BinarySearchTree()

        self.one_node_bst = BinarySearchTree()
        self.one_node_bst.insert(1)

        #     ______8
        #    /       \
        #   3__       10___
        #  /   \           \
        # 1     6          _14
        #      / \        /
        #     4   7      13
        self.insert_items = [8, 3, 10, 1, 6, 14, 4, 7, 13]
        self.bst = BinarySearchTree()
        for i in self.insert_items:
            self.bst.insert(i)

        array = binarytree.bst(is_perfect=True).values
        self.perfect_bst = BinarySearchTree.from_array_representation(array)