def test_is_empty(self): s = Queue() self.assertTrue(s.is_empty()) s.enqueue(2) self.assertFalse(s.is_empty()) s.dequeue() self.assertTrue(s.is_empty())
def test_dequeue(self): q = Queue() self.assertRaises(EmptyQueue, q.dequeue) q.enqueue(3) q.enqueue("a") self.assertEqual(q.dequeue(), 3) self.assertEqual(q.dequeue(), "a")
def test_Queue(self): self.assertIn('__init__', dir(Queue)) self.assertIn('dequeue', dir(Queue)) self.assertIn('is_empty', dir(Queue)) testins = Queue() testins.enqueue(1) testins.enqueue("two") self.assertEqual(testins.queue, [1, "two"]) testins.dequeue() self.assertEqual(testins.queue, ["two"]) self.assertEqual(testins.is_empty(), False) self.assertEqual(testins.size(), 1) testins.dequeue() self.assertEqual(testins.is_empty(), True) self.assertEqual(testins.queue, []) self.assertRaises(EmptyQueue, testins.dequeue)
class QueueTests(unittest.TestCase): def setUp(self): self.que = Queue() def test_dequeue(self): self.assertRaises(EmptyQueue, self.que.dequeue) self.que.enqueue('a') self.que.enqueue('b') self.assertEqual(self.que.dequeue(), 'b') def test_is_empty(self): self.assertTrue(self.que.is_empty()) self.que.enqueue('test') self.assertFalse(self.que.is_empty()) def test_size(self): self.assertEqual(self.que.size(), 0) self.que.enqueue('test') self.assertEqual(self.que.size(), 1)
def test_dequeue(self): s = Queue() s.enqueue(2) self.assertEqual(s.dequeue(), 2)
def test_size(self): q = Queue() q.enqueue(4) self.assertEqual(q.size(), 1) q.dequeue() self.assertEqual(q.size(), 0)