Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
    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)
Exemple #4
0
    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
Exemple #5
0
    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])
Exemple #6
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)
Exemple #7
0
 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
Exemple #8
0
    def test_insert_p4(self, vs):
        bst = impl.BST()
        for x in vs:
            assert bst.insert(x)

        self.isbst(bst.root)
Exemple #9
0
    def test_search_p2(self, vs):
        bst = impl.BST()
        for x in vs:
            bst.insert(x)

        assert bst.search(vs[0])
Exemple #10
0
 def test_root_p9(self):
     bst = impl.BST()
     assert not bst.root
Exemple #11
0
def test_new_bst_should_have_none_root():
    bst = impl.BST()
    assert bst.root == None
Exemple #12
0
def test_successful_insert_followed_by_successful_search(values):
    bst = impl.BST()
    for v in values:
        if bst.insert(v):
            assert bst.search(v)
Exemple #13
0
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)