Skip to content

Instantly share code, notes, and snippets.

@zedr
Last active January 29, 2025 11:00
Show Gist options
  • Save zedr/aedaffe1ba8667c10d84968ee6918ae9 to your computer and use it in GitHub Desktop.
Save zedr/aedaffe1ba8667c10d84968ee6918ae9 to your computer and use it in GitHub Desktop.
linked_lists_tests.py
# Implement a file named linked_lists.py
from linked_lists import LinkedList, Node
# Part 1 - tests for the nodes of a linked list
head_node = Node("Napoli")
assert head_node.next is None
head_node.next = Node("Rome")
head_node.next.next = Node("Milan")
# Part 2 - tests for the linked list
my_list = LinkedList()
assert len(my_list) == 0
assert my_list.head is None
my_list.add_node(data="Napoli")
assert len(my_list) == 1
assert my_list.head.data == "Napoli"
my_list.add_node(data="Milan")
assert len(my_list) == 2
# Check that we have two objects of type Node
assert [type(el) for el in my_list] == [Node, Node]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment