示例#1
0
 def test_queue_fill_empty_queue(self):
     n = 5
     q = Queue(n)
     self.assertTrue(q.is_empty())
     self.assertFalse(q.is_full())
     self.assertEqual(q.size(), 0)
     for step in range(1, n):
         q.enqueue(step)
         self.assertEqual(q.size(), step)
         self.assertFalse(q.is_full())
         self.assertFalse(q.is_empty())
     self.assertEqual(q.size(), n - 1)
     q.enqueue(n)
     self.assertEqual(q.size(), n)
     self.assertTrue(q.is_full())
     self.assertFalse(q.is_empty())
     for step in range(1, n):
         self.assertEqual(q.size(), n - (step - 1))
         self.assertEqual(q.dequeue(), step)
         self.assertFalse(q.is_full())
         self.assertFalse(q.is_empty())
     self.assertEqual(q.size(), 1)
     self.assertEqual(q.dequeue(), n)
     self.assertEqual(q.size(), 0)
     self.assertTrue(q.is_empty())
     self.assertFalse(q.is_full())
示例#2
0
 def test_queue(self):
     '''Trivial test to ensure method names and parameters are correct'''
     q = Queue(5)
     q.is_empty()
     q.is_full()
     q.enqueue('thing')
     q.dequeue()
     q.size()
示例#3
0
 def test_is_empty(self): # DONE
     """Created and testing empty queue"""
     my_q = Queue(5)
     self.assertTrue(my_q.is_empty())
     self.assertEqual(my_q.__repr__(), "Queue(5, None)")
     """Testing non-empty queue"""
     my_q.enqueue(3)
     self.assertFalse(my_q.is_empty())
示例#4
0
 def test_is_empty(self):
     q = Queue(3)
     self.assertTrue(q.is_empty())
     q.enqueue(32)
     self.assertFalse(q.is_empty())
     q.dequeue()
     self.assertTrue(q.is_empty())
     q.enqueue(32)
     q.enqueue(16)
     q.enqueue(44)
     self.assertFalse(q.is_empty())
示例#5
0
 def test_cap2(self):
     q = Queue(2)
     self.assertEqual(q.size(), 0)
     self.assertFalse(q.is_full())
     self.assertTrue(q.is_empty())
     q.enqueue(None)
     self.assertEqual(q.size(), 1)
     self.assertFalse(q.is_full())
     self.assertFalse(q.is_empty())
     self.assertEqual(q.dequeue(), None)
     self.assertEqual(q.size(), 0)
     self.assertTrue(q.is_empty())
     self.assertFalse(q.is_full())
     q.enqueue(1)
     self.assertEqual(q.size(), 1)
     self.assertFalse(q.is_full())
     self.assertFalse(q.is_empty())
     q.enqueue(2)
     self.assertEqual(q.size(), 2)
     self.assertTrue(q.is_full())
     self.assertFalse(q.is_empty())
     self.assertEqual(q.dequeue(), 1)
     self.assertEqual(q.size(), 1)
     self.assertFalse(q.is_full())
     self.assertFalse(q.is_empty())
     self.assertEqual(q.dequeue(), 2)
     self.assertEqual(q.size(), 0)
     self.assertFalse(q.is_full())
     self.assertTrue(q.is_empty())
     q.enqueue(1)
     self.assertEqual(q.size(), 1)
     self.assertFalse(q.is_full())
     self.assertFalse(q.is_empty())
示例#6
0
 def test_cap1(self):
     q = Queue(1)
     self.assertEqual(q.size(), 0)
     self.assertFalse(q.is_full())
     self.assertTrue(q.is_empty())
     q.enqueue(None)
     self.assertEqual(q.size(), 1)
     self.assertTrue(q.is_full())
     self.assertFalse(q.is_empty())
     with self.assertRaises(IndexError):
         q.enqueue(2)
     self.assertEqual(q.dequeue(), None)
     self.assertEqual(q.size(), 0)
     self.assertFalse(q.is_full())
     self.assertTrue(q.is_empty())
     with self.assertRaises(IndexError):
         q.dequeue()
     self.assertEqual(q.size(), 0)
     self.assertFalse(q.is_full())
     self.assertTrue(q.is_empty())
示例#7
0
 def test_dequeue(self):
     q = Queue(3)
     q.enqueue(4)
     q.enqueue(6)
     q.enqueue(22)
     self.assertEqual(q.dequeue(), 4)
     self.assertEqual(q.dequeue(), 6)
     self.assertEqual(q.num_items, 1)
     q.enqueue(12)
     self.assertEqual(q.dequeue(), 22)
     self.assertEqual(q.dequeue(), 12)
     self.assertTrue(q.is_empty())
     with self.assertRaises(IndexError):
         q.dequeue()
示例#8
0
 def test_queue_fill_to_cap_dequeue(self):
     n = 10
     q = Queue(n)
     self.assertEqual(q.size(), 0)
     self.assertTrue(q.is_empty())
     self.assertFalse(q.is_full())
     for step in range(1, n + 1):
         q.enqueue(step)
         self.assertFalse(q.is_empty())
         self.assertEqual(q.size(), step)
     self.assertTrue(q.is_full())
     for step in range(1, n + 1):
         self.assertEqual(q.dequeue(), step)
         self.assertFalse(q.is_full())
         self.assertEqual(q.size(), n - step)
     self.assertEqual(q.size(), 0)
     with self.assertRaises(IndexError):
         q.dequeue()
     self.assertTrue(q.is_empty())
     self.assertFalse(q.is_full())
     for step in range(1, n + 1):
         q.enqueue(step)
         self.assertFalse(q.is_empty())
         self.assertEqual(q.size(), step)
     self.assertTrue(q.is_full())
     with self.assertRaises(IndexError):
         q.enqueue("overfill")
     for step in range(1, n + 1):
         self.assertEqual(q.dequeue(), step)
         self.assertFalse(q.is_full())
         self.assertEqual(q.size(), n - step)
     self.assertEqual(q.size(), 0)
     self.assertTrue(q.is_empty())
     self.assertFalse(q.is_full())
     with self.assertRaises(IndexError):
         q.dequeue()
示例#9
0
 def test_enqueue_empty_full(self):
     q = Queue(0)
     self.assertTrue(q.is_empty())
     self.assertTrue(q.is_full())