#!/usr/bin/python #from digit import Solution #from anagram import Solution from stack import Queue answer = Queue() answer.push(1) answer.push(2) print 'should be 1' print answer.peek() answer.pop() print 'should be 2' print answer.peek() answer.empty() answer.pop() answer.pop() print 'should be none' print answer.peek()
def test_queue_002(self): q = Queue() self.assertTrue(q.is_empty()) q.enqueue('A') self.assertFalse(q.is_empty()) self.assertFalse(q.is_empty()) self.assertEqual(q.dequeue(), 'A') self.assertTrue(q.is_empty())
def test_dequeue(self): queue = Queue() queue.enqueue(1) queue.enqueue(2) queue.enqueue(3) self.assertEqual(queue.dequeue(), 1) self.assertEqual(queue.dequeue(), 2) self.assertEqual(queue.dequeue(), 3)
def test_queue_001(self): q = Queue() self.assertTrue(q.is_empty())
def test_queue_003(self): q = Queue() self.assertTrue(q.is_empty()) with self.assertRaises(QueueIsEmptyException): self.assertEqual(q.dequeue(), 'A')
from stack import Queue # s = Stack() # # s.push(32) # 32 # s.push(7) # 7 32 # d = s.pop() # 32 and d holds 7 # s.push(d) # 7 32 # s.pop() # 32 q = Queue() # [] q.enqueue(32) # [32] d = q.dequeue() # [] print(d) # 32 q.enqueue(32) # [32] q.enqueue(7) # [32 7] d = q.dequeue() # [7] d = 32 print(d) q.enqueue(32) # [7 32] a = q.peek() # 7 32 and a holds 32 print(a) print(q.size()) d = q.dequeue() dd = q.dequeue() print(d) print(dd) for i in range(0,10): q.enqueue(i)
def test_enqueue(self): queue = Queue() queue.enqueue(1) queue.enqueue(2) queue.enqueue(3) self.assertEqual(queue.values, [1, 2, 3])