def test_insertanddelete(): L = LinkedList() x = ListElement(0) L.LIST_INSERT(x) L.LIST_DELETE(x) assert L.nil.next == L.nil assert L.nil.prev == L.nil
def test_insertanddelete100fromhead(): L = LinkedList() for i in range(100): x = ListElement(i) L.LIST_INSERT(x) for i in range(100): assert L.nil.next.key == 99 - i L.LIST_DELETE(L.nil.next) assert L.nil.next == L.nil assert L.nil.prev == L.nil
def test_insertanddelete100fromtail(): L = LinkedList() for i in range(0, 100): x = ListElement(i) L.LIST_INSERT(x) z = L.nil.prev for i in range(100): assert z.key == i L.LIST_DELETE(z) z = z.prev assert L.nil.next == L.nil assert L.nil.prev == L.nil
def test_delete(): L = LinkedList() x = ListElement(0) L.LIST_INSERT(x) y = ListElement(1) L.LIST_INSERT(y) z = ListElement(2) L.LIST_INSERT(z) assert z.next == y assert y.prev == z assert y.next == x assert x.prev == y L.LIST_DELETE(y) assert z.next == x assert x.prev == z