Esempio n. 1
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)
Esempio n. 2
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()
Esempio n. 4
0
 def test_is_empty_on_creation(self):
     pq = PriorityQueue()
     self.assertTrue(pq.is_empty())
Esempio 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)
Esempio 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)
Esempio n. 7
0
 def test_cannot_pop_if_empty(self):
     pq = PriorityQueue()
     with self.assertRaises(RuntimeError):
         pq.pop()
Esempio n. 8
0
 def test_cannot_push_noninteger(self):
     pq = PriorityQueue()
     with self.assertRaises(TypeError):
         pq.push("notanumber")
Esempio n. 9
0
 def test_becomes_empty_after_last_pop(self):
     pq = PriorityQueue()
     pq.push(1)
     pq.pop()
     self.assertTrue(pq.is_empty())
Esempio n. 10
0
 def __init__(self):
     self.pq = PriorityQueue()
 def __init__(self, logger=RealLogger()):
     self.pq = PriorityQueue()
     self.logger = logger
     self.logger.log("Hello pqvm init")
Esempio n. 12
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)
Esempio n. 13
0
 def test_cannot_merge_with_wrong_arg(self):
     pq = PriorityQueue()
     with self.assertRaises(TypeError):
         pq.merge("notaPQ")
Esempio n. 14
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)