def test_prepend_valid_list_prepend_node_is_head(self):
        node_string = SinglyNode('head')

        self.linkedlist.prepend(node_string)

        self.assertIs(self.linkedlist.head, node_string)
        self.assertEqual(node_string.next, self.nodes[0])
        self.assertEqual(len(self.linkedlist), 4)
    def test_push_empty_stack_top_is_node(self):
        node = SinglyNode(0)
        stack = Stack()

        stack.push(node)

        self.assertIs(stack.top, node)
        self.assertEqual(len(stack), 1)
    def test_enqueue_empty_queue__head_and_tail_same_node(self):
        node = SinglyNode(0)
        queue = Queue()
        queue.enqueue(node)

        self.assertIs(queue.head, node)
        self.assertIs(queue.tail, node)
        self.assertEqual(len(queue), 1)
    def test_append_empty_list_append_node_is_tail(self):
        node = SinglyNode('head')
        linkedlist = SinglyLinkedList()

        linkedlist.append(node)

        self.assertIs(linkedlist.tail, node)
        self.assertEqual(len(linkedlist), 1)
    def test_push_valid_stack_adds_node(self):
        node = SinglyNode(10)
        self.stack.push(node)

        nodes = self.nodes + [node]

        for n, s in zip(reversed(nodes), self.stack):
            self.assertIs(n, s)
        self.assertEqual(len(self.stack), 11)
    def test_insert_empty_list_head_and_tail_is_same_node(self):
        node = SinglyNode('head')
        linkedlist = SinglyLinkedList()
        SinglyLinkedList.insert(linkedlist, node)

        self.assertIs(linkedlist.head, node)
        self.assertIs(linkedlist.tail, node)
        self.assertIsNone(node.next)
        self.assertEqual(len(linkedlist), 1)
    def test_prepend_empty_list_prepend_node_is_head_and_tail(self):
        node_string = SinglyNode('head')
        linkedlist = SinglyLinkedList()

        linkedlist.prepend(node_string)

        self.assertIs(linkedlist.head, node_string)
        self.assertIs(linkedlist.tail, node_string)
        self.assertIsNone(linkedlist.head.next)
        self.assertEqual(len(linkedlist), 1)
    def test_delitem_valid_list_delete_non_existent_node_raises_lookuperror(
            self):  # noqa E501
        node = SinglyNode('nonexistent')

        self.assertRaises(LookupError, self.linkedlist.__delitem__, node)
    def test_getitem_valid_list_get_nonexistent_node_raises_lookuperror(self):
        node = SinglyNode(None)

        self.assertRaises(LookupError, self.linkedlist.__getitem__, node.value)
    def test_enqueue_valid_queue_enqueue_adds_node_to_tail(self):
        node = SinglyNode(10)
        self.queue.enqueue(node)

        self.assertIs(self.queue.tail, node)
        self.assertIs(self.queue.head, self.nodes[0])
 def setUp(self):
     self.nodes = [SinglyNode(x) for x in range(10)]
     self.queue = Queue()
     for n in self.nodes:
         self.queue.enqueue(n)
 def setUp(self):
     self.nodes = [SinglyNode(x) for x in range(10)]
     self.stack = Stack()
     for n in self.nodes:
         self.stack.push(n)
 def test_delete_valid_list_nonexistent_node_lookuperror(self):
     with self.assertRaises(LookupError):
         del self.linkedlist[SinglyNode('nonexistent')]
    def test_insert_valid_list_head_is_new_node(self):
        node = SinglyNode('head')
        SinglyLinkedList.insert(self.linkedlist, node)

        self.assertIs(self.linkedlist.head, node)
        self.assertEqual(len(self.linkedlist), 4)
    def test_append_valid_list_append_node_is_tail(self):
        node = SinglyNode('tail')
        self.linkedlist.append(node)

        self.assertIs(self.linkedlist.tail, node)
        self.assertEqual(len(self.linkedlist), 4)
    def setUp(self):
        self.linkedlist = SinglyLinkedList()
        self.nodes = [SinglyNode(x) for x in range(3)]

        for n in self.nodes:
            self.linkedlist.append(n)