]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
check_invariant(): Use the same child->parent "formula" used by heapq.py.
authorTim Peters <tim.peters@gmail.com>
Fri, 2 Aug 2002 19:41:54 +0000 (19:41 +0000)
committerTim Peters <tim.peters@gmail.com>
Fri, 2 Aug 2002 19:41:54 +0000 (19:41 +0000)
Lib/test/test_heapq.py

index 016fd3af41edbb024afed3d91d5c8bf268033940..879899e35cac72bf442c39dc478afc0551916b39 100644 (file)
@@ -8,8 +8,8 @@ import random
 def check_invariant(heap):
     # Check the heap invariant.
     for pos, item in enumerate(heap):
-        parentpos = ((pos+1) >> 1) - 1
-        if parentpos >= 0:
+        if pos: # pos 0 has no parent
+            parentpos = (pos-1) >> 1
             verify(heap[parentpos] <= item)
 
 def test_main():