def test_delete(self):
     q=Queue()
     q.enqueue(1)
     q.enqueue(2)
     assert q.data==[1,2]
     q.dequeue()
     assert q.data==[2]
Esempio n. 2
0
class QueueSizeTestCase(unittest.TestCase):
    def setUp(self):
        self.queue = Queue()

    def test_size_should_return_the_number_of_items_in_the_queue(self):
        self.assertEqual(self.queue.size(), 0)

        self.queue.enqueue(1)
        self.assertEqual(self.queue.size(), 1)

        self.queue.enqueue(2)
        self.assertEqual(self.queue.size(), 2)

        self.queue.dequeue()
        self.assertEqual(self.queue.size(), 1)

        self.queue.front()
        self.assertEqual(self.queue.size(), 1)

        self.queue.rear()
        self.assertEqual(self.queue.size(), 1)
Esempio n. 3
0
class QueueRearTestCase(unittest.TestCase):
    def setUp(self):
        self.queue = Queue()
        self.queue.enqueue(1)
        self.queue.enqueue(2)
        self.queue.enqueue(3)

    def test_rear_should_return_the_last_item_of_its_items_list(self):
        self.assertEqual(self.queue.rear(), 3)
        self.assertEqual(self.queue.rear(), 3)
        self.assertEqual(self.queue.rear(), 3)

    def test_rear_should_return_none_if_queue_is_already_empty(self):
        self.queue.dequeue()
        self.queue.dequeue()
        self.queue.dequeue()
        self.assertEqual(self.queue.rear(), None)

    def test_rear_should_not_decrement_queue_size(self):
        self.assertEqual(self.queue.size(), 3)

        self.queue.rear()
        self.assertEqual(self.queue.size(), 3)