예제 #1
0
파일: test_heap.py 프로젝트: mindis/learn
 def test_heapify(self):
     h = IndexedHeap.heapify([(3, 'z'), (2, 'y'), (1, 'x')])
     expected = [
         {'key': 1, 'value': 'x', 'index': 0},
         {'key': 2, 'value': 'y', 'index': 1},
         {'key': 3, 'value': 'z', 'index': 2}
     ]
     self.assertItemsEqual(expected, h.data, 'should create a valid heap')
예제 #2
0
 def test_heapify(self):
     h = IndexedHeap.heapify([(3, 'z'), (2, 'y'), (1, 'x')])
     expected = [{
         'key': 1,
         'value': 'x',
         'index': 0
     }, {
         'key': 2,
         'value': 'y',
         'index': 1
     }, {
         'key': 3,
         'value': 'z',
         'index': 2
     }]
     self.assertItemsEqual(expected, h.data, 'should create a valid heap')
예제 #3
0
 def test_extract_min(self):
     h = IndexedHeap.heapify([('z', 3), ('y', 2), ('x', 1)])
     item = h.extract_min()
     expected = {'key': 'x', 'value': 1, 'index': 0}
     self.assertEqual(expected, item, 'correctly extracts the min value')
예제 #4
0
파일: test_heap.py 프로젝트: mindis/learn
 def test_extract_min(self):
     h = IndexedHeap.heapify([('z', 3), ('y', 2), ('x', 1)])
     item = h.extract_min()
     expected = {'key': 'x', 'value': 1, 'index': 0}
     self.assertEqual(expected, item, 'correctly extracts the min value')