예제 #1
0
def test_find2():
    tree = Tree()
    l = [38, 13, 51, 10, 25, 40, 84, 12, 37, 66, 89, 95]
    length = len(l)
    while len(l) > 0:
        key = l.pop(0)
        value = chr(key)
        tree.insert(key, value)
    assert tree.find(100).key == 95
    assert tree.find(50).key == 40
    assert tree.find(39).key == 40
    assert tree.find(15).key == 25
예제 #2
0
def test_find():
    l = list()
    for i in range(97, 107):
        l.append(i)

    tree = Tree()
    random.shuffle(l)
    while len(l) > 0:
        key = l.pop()
        value = chr(key)
        tree.insert(key, value)

    for i in range(97, 107):
        key = i
        value = chr(key)
        croot = tree.find(key)
        assert croot.value == value
예제 #3
0
def test_remove5():

    tree = Tree()
    l = list()
    s = 100
    for i in range(0, s):
        tree.insert(i, i)

    for i in range(0, s):
        l.append(i)
    random.shuffle(l)

    size = 100
    while len(l) > 1:
        key = l.pop()
        tree.remove(key)
        size -= 1
        assert len(tree.in_order()) == size
        croot = tree.find(key)
        assert croot.key != key
예제 #4
0
def test_remove():
    tree = Tree()
    l = [38, 13, 51, 10, 25, 40, 84, 12, 37, 66, 89, 95]
    length = len(l)
    while len(l) > 0:
        key = l.pop(0)
        value = chr(key)
        tree.insert(key, value)

    tree.remove(38)
    assert tree.root.key == 37
    assert tree.find(13).parent.key == 37
    assert tree.find(51).parent.key == 37
    assert tree.find(38).key == 40

    tree.remove(89)
    assert tree.find(95).key == 95
    assert tree.find(95).parent.key == 84

    tree.remove(13)
    assert tree.find(13).key == 25
    assert tree.find(12).parent.key == 37
    assert tree.find(10).parent.key == 12
    assert tree.find(25).parent.key == 12