Beispiel #1
0
 def test_length_after_append_and_prepend(self):
     ll = LinkedList()
     assert ll.length() == 0
     # Append and prepend should increase length
     ll.append('C')
     assert ll.length() == 1
     ll.prepend('B')
     assert ll.length() == 2
     ll.append('D')
     assert ll.length() == 3
     ll.prepend('A')
     assert ll.length() == 4
Beispiel #2
0
 def test_items_after_append(self):
     ll = LinkedList()
     assert ll.items() == []
     # Append should add new item to tail of list
     ll.append('A')
     assert ll.items() == ['A']
     ll.append('B')
     assert ll.items() == ['A', 'B']
     ll.append('C')
     assert ll.items() == ['A', 'B', 'C']
Beispiel #3
0
 def test_append(self):
     ll = LinkedList()
     # Append should always update tail node
     ll.append('A')
     assert ll.head.data == 'A'  # New head
     assert ll.tail.data == 'A'  # New tail
     ll.append('B')
     assert ll.head.data == 'A'  # Unchanged
     assert ll.tail.data == 'B'  # New tail
     ll.append('C')
     assert ll.head.data == 'A'  # Unchanged
     assert ll.tail.data == 'C'  # New tail