Beispiel #1
0
def test_hookchain():
    hc = Heap()
    assert hc.hook is None
    hc.add_hook(1)
    hc.add_hook(2)
    hc.add_hook(3)
    assert hc.hook.attvar == 3
    assert hc.hook.next.attvar == 2
    assert hc.hook.next.next.attvar == 1
    assert hc.hook.next.next.next is None
Beispiel #2
0
def test_hookchain_size():
    def size(heap):
        # for tests only
        if heap.hook is None:
            return 0
        current = heap.hook
        size = 0
        while current is not None:
            current = current.next
            size += 1
        return size
    h = Heap()
    assert size(h) == 0
    h.add_hook(1)
    assert size(h) == 1
    h.add_hook(2)
    assert size(h) == 2
    h.hook = None
    assert size(h) == 0