def test_eq(self): c = 'WHAT' my_q = Queue(2) my_q.enqueue(c) my_q2 = Queue(2) my_q2.enqueue(c) self.assertEquals(my_q.__eq__(my_q2), True)
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())
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())
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()
def test_size(self): my_q = Queue(5) my_q.enqueue('C') my_q.enqueue('-') my_q.enqueue(3) self.assertTrue(my_q.size(), 3)
def test_is_full(self): q = Queue(3) q.enqueue(4) q.enqueue(6) q.enqueue(22) q2 = Queue(2) self.assertFalse(q2.is_full()) self.assertTrue(q.is_full()) q.dequeue() self.assertFalse(q.is_full()) q.enqueue(32) self.assertTrue(q.is_full()) q2.enqueue(123) q2.enqueue(0) self.assertTrue(q2.is_full())
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())
def test_size(self): q = Queue(1) q.enqueue("fill") self.assertEqual(q.size(),1)
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()
def test_repr(self): """Creating empty queue""" my_q = Queue(4) """enqueueing node""" my_q.enqueue('Luis') my_q.enqueue('Gomez') my_q.enqueue('is') my_q.enqueue('chill') self.assertEqual(my_q.__repr__(), "Queue(4, Node('Luis', Node('Gomez', Node('is', Node('chill', None)))))")
def setUp(self): self.q = Queue()
class QueueTests(unittest.TestCase): def setUp(self): self.q = Queue() def test_len_returns_0_for_empty_queue(self): self.assertEqual(len(self.q), 0) def test_len_returns_correct_length_after_enqueue(self): self.assertEqual(len(self.q), 0) self.q.enqueue(2) self.assertEqual(len(self.q), 1) self.q.enqueue(4) self.assertEqual(len(self.q), 2) self.q.enqueue(6) self.q.enqueue(8) self.q.enqueue(10) self.q.enqueue(12) self.q.enqueue(14) self.q.enqueue(16) self.q.enqueue(18) self.assertEqual(len(self.q), 9) def test_empty_dequeue(self): self.assertIsNone(self.q.dequeue()) self.assertEqual(len(self.q), 0) def test_dequeue_respects_order(self): self.q.enqueue(100) self.q.enqueue(101) self.q.enqueue(105) self.assertEqual(self.q.dequeue(), 100) self.assertEqual(len(self.q), 2) self.assertEqual(self.q.dequeue(), 101) self.assertEqual(len(self.q), 1) self.assertEqual(self.q.dequeue(), 105) self.assertEqual(len(self.q), 0) self.assertIsNone(self.q.dequeue()) self.assertEqual(len(self.q), 0)
def test_size(self): q = Queue(4) q2 = Queue(3) q2.enqueue(4) q2.enqueue(6) q2.enqueue(22) self.assertEqual(q.size(), 0) self.assertEqual(q2.size(), 3) q.enqueue(13) q2.dequeue() self.assertEqual(q.size(), 1) self.assertEqual(q2.size(), 2)
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()
def test_enqueue(self): q = Queue(3) q.enqueue(8) self.assertEqual(q.rear.data, 8) q.enqueue(42) self.assertEqual(q.num_items, 2) self.assertEqual(q.rear.data, 42) q.enqueue(76) self.assertEqual(q.rear.data, 76) q.dequeue() q.enqueue(23) self.assertEqual(q.rear.data, 23) self.assertTrue(q.is_full()) with self.assertRaises(IndexError): q.enqueue(1)
def test_enqueue_empty_full(self): q = Queue(0) self.assertTrue(q.is_empty()) self.assertTrue(q.is_full())
def test_dequeue_error(self): q = Queue(0) with self.assertRaises(IndexError): q.dequeue()
def test_is_full(self): # DONE """Creating full queue""" my_q = Queue(5) my_q.enqueue(100) my_q.enqueue(-100) my_q.enqueue(-95) my_q.enqueue(100.5) my_q.enqueue(0) self.assertTrue(my_q.is_full()) """Testing empty queue""" my_q2 = Queue(5) self.assertFalse(my_q2.is_full())
def test_enqueue_error(self): q = Queue(1) q.enqueue(1) with self.assertRaises(IndexError): q.enqueue("miss")
def test_enqueue(self): """Creating empty queue""" my_q = Queue(4) """enqueueing node""" my_q.enqueue('Luis') my_q.enqueue('Gomez') my_q.enqueue('is') my_q.enqueue('chill') """queue is full, enqueue returns index error""" with self.assertRaises(IndexError): my_q.enqueue(4)
def test_enqueue_dequeue_no_cap(self): q = Queue(0) with self.assertRaises(IndexError): q.dequeue()
def test_dequeue(self): """Create full queue""" my_q = Queue(5) my_q.enqueue('C') my_q.enqueue('-') my_q.enqueue(3) my_q.enqueue('P') my_q.enqueue('O') self.assertEqual(my_q.__repr__(), "Queue(5, Node('C', Node('-', Node(3, Node('P', Node('O', None))))))") """Testing if dequeue returns Node with empty next pointer""" self.assertEqual(my_q.dequeue(), 'C') """queue should now have 1 less item, good!""" self.assertEqual(my_q.__repr__(), "Queue(5, Node('-', Node(3, Node('P', Node('O', None)))))") """Testing empty queue""" my_q2 = Queue(4) with self.assertRaises(IndexError): my_q2.dequeue()
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())
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())