コード例 #1
0
ファイル: test_heap.py プロジェクト: mindis/learn
    def test_remove(self):
        """ Test the removal of a key from the middle of the heap.
        Given the following heap:
                        (4)
                       /   \
                    (4)    (8)
                   /  \    /  \
                 (9) (4) (12) (9)
                /  \
             (11)  (13)
        """
        data = [4, 4, 8, 9, 4, 12, 9, 11, 13]
        h = Heap(data)
        h.remove(2)

        self.assertTrue(Heap.is_heap(data), 'should preserve heap property')
        self.assertNotIn(8, h.data, 'the value corresponding to the index was removed')
コード例 #2
0
    def remove(self, vertex):
        """ Overrides parent method to remove a vertex by it's vertex not cost.

        Args
            vertex: str, name of the vertex to remove.
        """
        index = map(itemgetter(0), self.data).index(vertex)
        return Heap.remove(self, index)
コード例 #3
0
ファイル: test_heap.py プロジェクト: elverkilde/learn
    def test_remove(self):
        """ Test the removal of a key from the middle of the heap.
        Given the following heap:
                        (4)
                       /   \
                    (4)    (8)
                   /  \    /  \
                 (9) (4) (12) (9)
                /  \
             (11)  (13)
        """
        data = [4, 4, 8, 9, 4, 12, 9, 11, 13]
        h = Heap(data)
        h.remove(2)

        self.assertTrue(Heap.is_heap(data), 'should preserve heap property')
        self.assertNotIn(8, h.data,
                         'the value corresponding to the index was removed')
コード例 #4
0
ファイル: test_heap.py プロジェクト: elverkilde/learn
 def test_remove_if_one_element(self):
     data = [3]
     h = Heap(data)
     h.remove(0)
     self.assertEqual(h.data, [], 'should remove the only elem in heap')
     self.assertTrue(Heap.is_heap(h.data), 'should maintain heap invariant')
コード例 #5
0
ファイル: test_heap.py プロジェクト: elverkilde/learn
 def test_remove_if_index_is_last(self):
     data = [3, 4, 5]
     h = Heap(data)
     h.remove(2)
     self.assertEqual(h.data, [3, 4], 'should remove the last leaf')
     self.assertTrue(Heap.is_heap(h.data), 'should maintain heap invariant')
コード例 #6
0
ファイル: test_heap.py プロジェクト: elverkilde/learn
 def test_remove_if_index_is_root(self):
     data = [3, 4, 5]
     h = Heap(data)
     h.remove(0)
     self.assertEqual(h.data, [4, 5], 'should remove the root')
     self.assertTrue(Heap.is_heap(h.data), 'should maintain heap invariant')
コード例 #7
0
ファイル: test_heap.py プロジェクト: mindis/learn
 def test_remove_if_one_element(self):
     data = [3]
     h = Heap(data)
     h.remove(0)
     self.assertEqual(h.data, [], 'should remove the only elem in heap')
     self.assertTrue(Heap.is_heap(h.data), 'should maintain heap invariant')
コード例 #8
0
ファイル: test_heap.py プロジェクト: mindis/learn
 def test_remove_if_index_is_last(self):
     data = [3, 4, 5]
     h = Heap(data)
     h.remove(2)
     self.assertEqual(h.data, [3, 4], 'should remove the last leaf')
     self.assertTrue(Heap.is_heap(h.data), 'should maintain heap invariant')
コード例 #9
0
ファイル: test_heap.py プロジェクト: mindis/learn
 def test_remove_if_index_is_root(self):
     data = [3, 4, 5]
     h = Heap(data)
     h.remove(0)
     self.assertEqual(h.data, [4,5], 'should remove the root')
     self.assertTrue(Heap.is_heap(h.data), 'should maintain heap invariant')