示例#1
0
 def test3(self):
     pq = min_PQ()
     pq.heap = [1, 3, 5]
     min = pq.remove_min()
     self.assertEqual(min, 1)
     self.assertEqual(len(pq.heap), 2)
     self.assertEqual(pq.heap, [3, 5])
示例#2
0
 def test4(self):
     pq = min_PQ()
     pq.heap = [1, 2, 3, 4, 5, 6, 7]
     try:
         pq.check_invariant()
     except RuntimeError():
         self.fail('Unexpected - heap invariant violated')
示例#3
0
 def test2(self):
     pq = min_PQ()
     pq.heap = [5, 10]
     min = pq.remove_min()
     self.assertEqual(min, 5)
     self.assertEqual(len(pq.heap), 1)
     self.assertEqual(pq.heap, [10])
示例#4
0
 def test2(self):
     pq = min_PQ()
     pq.heap = [68]
     try:
         pq.check_invariant()
     except RuntimeError:
         self.fail('Unexpected - heap invariant violated')
示例#5
0
 def test5(self):
     pq = min_PQ()
     pq.heap = [1, 3, 5, 10, 11, 6]
     min = pq.remove_min()
     self.assertEqual(min, 1)
     self.assertEqual(len(pq.heap), 5)
     self.assertEqual(pq.heap, [3, 6, 5, 10, 11])
示例#6
0
 def test4(self):
     pq = min_PQ()
     pq.heap = [1, 3, 5, 6, 4, 8]
     min = pq.remove_min()
     self.assertEqual(min, 1)
     self.assertEqual(len(pq.heap), 5)
     self.assertEqual(pq.heap, [3, 4, 5, 6, 8])
示例#7
0
 def test1(self):
     pq = min_PQ()
     self.assertRaises(IndexError, pq.remove_min)
示例#8
0
 def test4(self):
     pq = min_PQ()
     pq.heap = [5, 8, 11, 13, 14, 12, 17, 19]
     pq.insert(10)
     self.assertEqual(len(pq.heap), 9)
     self.assertEqual(pq.heap, [5, 8, 11, 10, 14, 12, 17, 19, 13])
示例#9
0
 def test3(self):
     pq = min_PQ()
     pq.heap = [2, 5, 7, 8, 9]
     pq.insert(1)
     self.assertEqual(len(pq.heap), 6)
     self.assertEqual(pq.heap, [1, 5, 2, 8, 9, 7])
示例#10
0
 def test2(self):
     pq = min_PQ()
     pq.heap = [5]
     pq.insert(7)
     self.assertEqual(len(pq.heap), 2)
     self.assertEqual(pq.heap, [5, 7])
示例#11
0
 def test1(self):
     pq = min_PQ()
     pq.insert(10)
     self.assertEqual(len(pq.heap), 1)
     self.assertEqual(pq.heap, [10])
示例#12
0
 def test3(self):
     pq = min_PQ()
     pq.heap = [2, 3, 5, 4, 1, 6]
     self.assertRaises(RuntimeError, pq.check_invariant)