Ejemplo n.º 1
0
 def test_can_merge_two_queues(self):
     pq1 = PriorityQueue()
     pq2 = PriorityQueue()
     pq1.push(2)
     pq2.push(1)
     pq1.merge(pq2)
     self.assertEqual(pq1.top(), 1)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
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()
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 def test_getting_topmin(self):
     pq = PriorityQueue()
     for v in [5, 4, 2, 3]:
         pq.push(v)
     self.assertEqual(pq.top(), 2)
Ejemplo n.º 7
0
 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)