示例#1
0
    def test3(self):
        bst = BinarySearchTree(5)
        ints = []
        for val in ints:
            bst.insertion(val)

        self.assertEqual(post_order_dfs_iterative(bst.root), [5])
示例#2
0
    def test4(self):
        bst = BinarySearchTree(5)
        ints = []
        for val in ints:
            bst.insertion(val)

        self.assertEqual(post_order_dfs_recursive(bst.root, []), [5])
示例#3
0
 def test1(self):
     bst = BinarySearchTree(5)
     ints = [3, 5, 1, 2, -5, -9]
     for val in ints:
         bst.insertion(val)
     self.assertEqual(breadth_first_search(bst.root),
                      [[5], [3, 5], [1], [-5, 2], [-9]])
示例#4
0
    def test2(self):
        bst = BinarySearchTree(5)
        ints = [3, 5, 1, 2, -5, -9]
        for val in ints:
            bst.insertion(val)

        self.assertEqual(post_order_dfs_recursive(bst.root, []),
                         [-9, -5, 2, 1, 3, 5, 5])
示例#5
0
    def testLookup(self):
        bst = BinarySearchTree(4)
        ints = [1, 2, 3, 5, 6, 7, 8]
        for val in ints:
            bst.insertion(val)

        for val in ints:
            self.assertEqual(bst.lookup(val).val, val)
示例#6
0
    def testDelete(self):
        bst = BinarySearchTree(4)
        ints = [1, 2, 3, 5, 6, 7, 8]
        for val in ints:
            bst.insertion(val)

        bst.delete(5)
        bst.delete(4)
        self.assertEqual(None, bst.lookup(5))
        self.assertEqual(None, bst.lookup(4))
        self.assertEqual(validateBST(bst), True)
示例#7
0
    def testInsertion(self):
        bst = BinarySearchTree(3)
        for val in range(8):
            bst.insertion(val)

        self.assertEqual(validateBST(bst), True)