def test_left_append(self): ll = LinkedList() ll.left_append(3) ll.left_append(1000) self.assertEqual(ll.head.data, 1000) self.assertEqual(ll.head.pointer_next.data, 3) self.assertIsNone(ll.head.pointer_next.pointer_next)
def test__iter__(self): ll = LinkedList() ll.right_append(100) ll.right_append(99) ll.left_append(0) iterator = iter(ll) self.assertEqual(next(iterator), 0) self.assertEqual(next(iterator), 100) self.assertEqual(next(iterator), 99) self.assertRaises(StopIteration, next, iterator)
def test_left_append_empty_list(self): ll = LinkedList() ll.left_append(10) self.assertCountEqual(ll, LinkedList(Node(10)))
from Linked_List import LinkedList if __name__ == '__main__': """ help() The Python help function can be super helpful for easily pulling up documentation for classes and methods. We can call the help function on one of our classes, which will return some basic info about the methods defined in our class """ """create LinkedList""" n1 = Node(1) n2 = Node(7) n1.pointer_next = n2 ll = LinkedList(n1) ll.left_append(100) print(ll) # # ll = LinkedList() # print(ll) # if ll: # print("Not empty!") """length of LinkedList""" # print(len(ll)) """append to left""" # print(ll) # ll.left_append(42) # ll.left_append(2) # print(ll) """check list for emptiness""" # if ll.is_empty():