def test_node_creation(self): name = "Jose" phone = "123-456-7890" node = Node(name, phone) self.assertEqual(name, node.name) self.assertEqual(phone, node.telephone)
def test_find_in_queue(self): name = "Jose" phone = "123-456-7890" node = Node(name, phone) queue = LinkedQueue() queue.push(node) self.assertEqual(queue.find(name), node)
def test_push_to_queue(self): name = "Jose" phone = "123-456-7890" node = Node(name, phone) queue = LinkedQueue() queue.push(node) self.assertEqual(len(queue), 1)
def test_add_to_list_start(self): name = "Jose" phone = "123-456-7890" node = Node(name, phone) linked_list = LinkedList() linked_list.add_start_to_list(node) self.assertEqual(linked_list.get_root(), node)
def test_pop_from_queue(self): name = "Jose" phone = "123-456-7890" node = Node(name, phone) queue = LinkedQueue() queue.push(node) self.assertEqual(len(queue), 1) popped = queue.pop() self.assertEqual(popped, node) self.assertEqual(len(queue), 0)
def test_find_in_list(self): names = ("Jose", "1234-356"), ("Rolf", "2345-1-53563-2"), ("Anna", "345623-16779-3") nodes = [Node(name, phone) for name, phone in names] linked_list = LinkedList() for node in nodes: linked_list.add_start_to_list(node) marker = linked_list.get_root() for i in range(len(nodes) - 1, -1, -1): self.assertEqual(linked_list.find(marker.name), nodes[i]) marker = marker.get_next()
def test_remove_end_from_list(self): names = ("Jose", "1234-356"), ("Rolf", "2345-1-53563-2"), ("Anna", "345623-16779-3") nodes = [Node(name, phone) for name, phone in names] linked_list = LinkedList() for node in nodes: linked_list.add_start_to_list(node) self.assertIsNotNone(linked_list.find("Jose")) popped_node = linked_list.remove_end_from_list() self.assertEqual(popped_node, nodes[0]) with self.assertRaises(LookupError): linked_list.find("Jose")
from queue_list_su.linkedlist import LinkedList from queue_list_su.node import Node from queue_list_su.linkedqueue import LinkedQueue names = ("Jose", "1234-356"), ("Rolf", "2345-1-53563-2"), ("Anna", "345623-16779-3"), ("Dust", "123456-16779-3") nodes = [Node(name, phone) for name, phone in names] # # linked_list = LinkedList() # # for node in nodes: # linked_list.add_start_to_list(node) # # # popped_node = linked_list.remove_end_from_list() # # print(popped_node) # linked_list.print_list() # popped_node = linked_list.remove_end_from_list() # # print(popped_node) # linked_list.print_list() #------------------------Queue----------------- linked_queue = LinkedQueue() for node in nodes: linked_queue.push(node) print(len(linked_queue))