def test_ascending_min_after_pop(self): pq = PriorityQueue() for v in [1, 2, 3, 4]: pq.push(v) pq.pop() pq.pop() pq.pop() self.assertEqual(pq.top(), 4)
class PriorityQueueViewModel: def __init__(self): self.pq = PriorityQueue() def push(self, e): self.pq.push(e) def top(self): return str(self.pq.top()) def pop(self): self.pq.pop() def is_empty(self): return self.pq.is_empty()
class PriorityQueueViewModel: def __init__(self, logger=RealLogger()): self.pq = PriorityQueue() self.logger = logger self.logger.log("Hello pqvm init") def push(self, e): self.logger.log("PQ push value") self.pq.push(e) def top(self): self.logger.log("PQ get top value") return str(self.pq.top()) def pop(self): self.logger.log("PQ pop value") self.pq.pop() def is_empty(self): return self.pq.is_empty()
def test_descending_min_after_pop(self): pq = PriorityQueue() for v in [4, 3, 2, 1]: pq.push(v) pq.pop() self.assertEqual(pq.top(), 2)
def test_cannot_pop_if_empty(self): pq = PriorityQueue() with self.assertRaises(RuntimeError): pq.pop()
def test_becomes_empty_after_last_pop(self): pq = PriorityQueue() pq.push(1) pq.pop() self.assertTrue(pq.is_empty())
def test_consistent_min_after_pop(self): pq = PriorityQueue() for v in [3, 2, 1]: pq.push(v) pq.pop() self.assertEqual(pq.top(), 2)