예제 #1
0
    def test_remove_tail(self):
        """Special case for remove, the node is the tail"""

        queue = LinkedListQueue([0, 1, 2, 3])
        tail = queue.enqueue(4)
        queue.remove(tail)
        self.assertEqual(len(queue.to_list()), 4)
        self.assertEqual(queue.tail.data, 3)
예제 #2
0
 def test_remove(self):
     queue = LinkedListQueue([0, 1, 2])
     node = queue.enqueue(3)
     queue.enqueue(4)
     queue.enqueue(5)
     queue.remove(node)
     self.assertEqual(queue.length, 5)
     self.assertEqual(len(queue.to_list()), 5)
예제 #3
0
 def test_remove(self):
     queue = LinkedListQueue([0, 1, 2])
     node = queue.enqueue(3)
     queue.enqueue(4)
     queue.enqueue(5)
     queue.remove(node)
     self.assertEqual(queue.length, 5)
     self.assertEqual(len(queue.to_list()), 5)
예제 #4
0
    def test_remove_tail(self):
        """Special case for remove, the node is the tail"""

        queue = LinkedListQueue([0, 1, 2, 3])
        tail = queue.enqueue(4)
        queue.remove(tail)
        self.assertEqual(len(queue.to_list()), 4)
        self.assertEqual(queue.tail.data, 3)
예제 #5
0
    def test_remove_head(self):
        """Special case for remove, the node is the head"""

        queue = LinkedListQueue()
        head = queue.enqueue(1)
        queue.remove(head)
        self.assertEqual(queue.empty(), True)
        self.assertEqual(queue.head, None)
        self.assertEqual(queue.tail, None)

        head = queue.enqueue(1)
        queue.enqueue(2)
        queue.remove(head)
        self.assertEqual(len(queue.to_list()), 1)
예제 #6
0
    def test_dequeue_empty(self):
        """Test dequeue an empty queue"""

        queue = LinkedListQueue()
        with self.assertRaises(RuntimeError):
            queue.dequeue()
예제 #7
0
 def test_dequeue(self):
     queue = LinkedListQueue([0, 1, 2, 3, 4])
     for i in xrange(5):
         data = queue.dequeue()
         self.assertEqual(data, i)
예제 #8
0
 def test_enqueue(self):
     queue = LinkedListQueue([1, 2, 3, 4])
     for i in xrange(6):
         queue.enqueue(i)
     self.assertEqual(queue.length, 10)
     self.assertEqual(len(queue.to_list()), 10)
예제 #9
0
    def test_remove_head(self):
        """Special case for remove, the node is the head"""

        queue = LinkedListQueue()
        head = queue.enqueue(1)
        queue.remove(head)
        self.assertEqual(queue.empty(), True)
        self.assertEqual(queue.head, None)
        self.assertEqual(queue.tail, None)

        head = queue.enqueue(1)
        queue.enqueue(2)
        queue.remove(head)
        self.assertEqual(len(queue.to_list()), 1)
예제 #10
0
    def test_dequeue_empty(self):
        """Test dequeue an empty queue"""

        queue = LinkedListQueue()
        with self.assertRaises(RuntimeError):
            queue.dequeue()
예제 #11
0
 def test_dequeue(self):
     queue = LinkedListQueue([0, 1, 2, 3, 4])
     for i in xrange(5):
         data = queue.dequeue()
         self.assertEqual(data, i)
예제 #12
0
 def test_enqueue(self):
     queue = LinkedListQueue([1, 2, 3, 4])
     for i in xrange(6):
         queue.enqueue(i)
     self.assertEqual(queue.length, 10)
     self.assertEqual(len(queue.to_list()), 10)