Пример #1
0
def treetest():
    t1 = LookupTree({0:0, 32:32, 4:4})
    assert t1.get(0) == 0
    t2 = t1.assoc(36, 36)
    assert t1.get(36) is None
    assert t2.get(36) == 36
    t3 = t2.assoc(36, 35)
    assert t3.get(36) == 35
    t4 = t2.multi_assoc([(15,15), (14,14)])
    assert t4.get(15) == 15
    assert t4.get(14) == 14
def treetest():
    t1 = LookupTree({0: 0, 32: 32, 4: 4})
    assert t1.get(0) == 0
    t2 = t1.assoc(36, 36)
    assert t1.get(36) is None
    assert t2.get(36) == 36
    t3 = t2.assoc(36, 35)
    assert t3.get(36) == 35
    t4 = t2.multi_assoc([(15, 15), (14, 14)])
    assert t4.get(15) == 15
    assert t4.get(14) == 14
Пример #3
0
def ugly_tree_creation_test():
    tree = LookupTree()
    error_values = []
    for i in range(10000):
        tree.insert(hash(i), (i, i))
        n = 0
        try:
            for k, v in tree:
                n += 1
            if n != i+1:
                error_values.append(i)
        except TypeError:
            # this is failing the first time through the loop, because
            # integers aren't iterable.
            # I'm torn about what to think about this fact.
            # Probably just means I don't understand the tree as well as I thought
            print "Quit being able to iterate over tree on insert # %d" % i
            raise
    assert not error_values
def ugly_tree_creation_test():
    tree = LookupTree()
    error_values = []
    for i in range(10000):
        tree.insert(hash(i), (i, i))
        n = 0
        try:
            for k, v in tree:
                n += 1
            if n != i + 1:
                error_values.append(i)
        except TypeError:
            # this is failing the first time through the loop, because
            # integers aren't iterable.
            # I'm torn about what to think about this fact.
            # Probably just means I don't understand the tree as well as I thought
            print "Quit being able to iterate over tree on insert # %d" % i
            raise
    assert not error_values