class QueueEnqueueTestCase(unittest.TestCase): def setUp(self): self.queue = Queue() def test_enqueue_should_add_item_to_the_end_of_items_list(self): self.queue.enqueue(1) self.assertEqual(self.queue.items[0], 1) self.queue.enqueue(2) self.assertEqual(self.queue.items[1], 2) def test_enqueue_should_incremement_queue_size(self): self.assertEqual(self.queue.size(), 0) self.queue.enqueue(1) self.assertEqual(self.queue.size(), 1)
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)
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)