def test_delete_works_dll(): s = ll.DLL(data=0) nodes = [s] for i in xrange(1, 10): nodes.append(ll.DLL(data=i)) ll.pushback(s, nodes[-1]) i = 7 ll.delete(nodes[3], nodes[i]) assert (nodes[i].data is None and nodes[i].nxt is None and nodes[i].prev is None) assert (nodes[i - 1].nxt == nodes[i + 1] and nodes[i + 1].prev == nodes[i - 1])
def test_inits_correctly(): s = ll.DLL(data=1, prev=2, nxt=3) assert s.data == 1 and s.prev == 2 and s.nxt == 3 s = ll.DLL(1, 2, 3) assert s.data == 1 and s.prev == 2 and s.nxt == 3
def test_deletes_correctly(): s = ll.DLL(1, 2, 3) s.delete() assert s.data is None and s.nxt is None and s.prev is None
def test_popfront_works_with_one_element(): s = ll.DLL(1) node = ll.popfront(s) assert node == s
def test_popback_works_with_one_element_dll(): s = ll.DLL(1) node = ll.popback(s) assert node == s
def setup(linked_list=True): if linked_list: return ll.LL(data=1), ll.LL(data=2) else: return ll.DLL(data=1), ll.DLL(data=2)
def test_pushfront_mixed_types_fail(): s = ll.LL(data=1) o = ll.DLL(data=2) for a, b in ((s, o), (o, s)): with pytest.raises(AssertionError): ll.pushfront(a, b)
def test_doubly_to_list(): head = ll.DLL(0) ll.pushback(head, ll.DLL(1)) ll.pushback(head, ll.DLL(2)) lst = ll.to_list(head) assert lst == range(3)
def test_delete_mixed_types_fail(): s = ll.LL(data=1) o = ll.DLL(data=2) for a, b in ((s, o), (o, s)): with pytest.raises(AssertionError): ll.delete(a, b)
def test_str_works(): head = ll.LL(0) assert str(head) == "0" head = ll.DLL(1) assert str(head) == "1"