Exemple #1
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)
Exemple #2
0
class QueueFrontTestCase(unittest.TestCase):
    def setUp(self):
        self.queue = Queue()
        self.queue.enqueue(1)
        self.queue.enqueue(2)
        self.queue.enqueue(3)

    def test_front_should_return_the_first_item_of_its_items_list(self):
        self.assertEqual(self.queue.front(), 1)
        self.assertEqual(self.queue.front(), 1)
        self.assertEqual(self.queue.front(), 1)

    def test_front_should_return_none_if_queue_is_already_empty(self):
        self.queue.dequeue()
        self.queue.dequeue()
        self.queue.dequeue()
        self.assertEqual(self.queue.front(), None)

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

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