def test_delete_p6(self, vs, r): bst = impl.BST() for x in vs: bst.insert(x) assert bst.delete(r.choice(vs)) self.isbst(bst.root)
def test_insert_p5(self, vs): bst = impl.BST() for x in vs: bst.insert(x) assert not bst.insert(vs[0]) self.isbst(bst.root)
def test_delete_search_p8(self, vs, r): bst = impl.BST() for x in vs: bst.insert(x) i = r.choice(vs) assert bst.delete(i) assert not bst.search(i)
def test_search_p10(self, vs, r): bst = impl.BST() for x in vs: bst.insert(x) init_bst = bst bst.search(r.choice(vs)) assert bst == init_bst
def test_search_p3(self, vs): bst = impl.BST() count = 0 for x in vs: if count != 0: bst.insert(x) count += 1 assert not bst.search(vs[0])
def test_bst_is_a_bst(values, op): bst = impl.BST() assert_tree_property(bst.root, set()) assert_binary_search_property(bst.root) ops = {1: bst.insert, 2: bst.delete, 3: bst.search} for v in values: for o in op: ops[o](v) assert_tree_property(bst.root, set()) assert_binary_search_property(bst.root)
def test_delete_p7(self, vs): bst = impl.BST() count = 0 for x in vs: if count != 0: bst.insert(x) count += 1 current_bst = bst assert not bst.delete(vs[0]) self.isbst(bst.root) assert current_bst == bst
def test_insert_p4(self, vs): bst = impl.BST() for x in vs: assert bst.insert(x) self.isbst(bst.root)
def test_search_p2(self, vs): bst = impl.BST() for x in vs: bst.insert(x) assert bst.search(vs[0])
def test_root_p9(self): bst = impl.BST() assert not bst.root
def test_new_bst_should_have_none_root(): bst = impl.BST() assert bst.root == None
def test_successful_insert_followed_by_successful_search(values): bst = impl.BST() for v in values: if bst.insert(v): assert bst.search(v)
def populate_tree(values): b = impl.BST() for v in values: b.insert(v) return b
def test_successful_insert_of_unique_values(values): bst = impl.BST() for v in set(values): assert bst.insert(v)