Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
0b191787
Kaydet (Commit)
0b191787
authored
Agu 02, 2002
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Adding the heap queue algorithm, per discussion in python-dev last
week.
üst
ad09bbfc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
test_heapq.py
Lib/test/test_heapq.py
+48
-0
No files found.
Lib/test/test_heapq.py
0 → 100644
Dosyayı görüntüle @
0b191787
"""Unittests for heapq."""
from
test.test_support
import
verify
,
vereq
,
verbose
,
TestFailed
from
heapq
import
heappush
,
heappop
import
random
def
check_invariant
(
heap
):
# Check the heap invariant.
for
pos
,
item
in
enumerate
(
heap
):
parentpos
=
(
pos
+
1
)
/
2
-
1
if
parentpos
>=
0
:
verify
(
heap
[
parentpos
]
<=
item
)
def
test_main
():
# 1) Push 100 random numbers and pop them off, verifying all's OK.
heap
=
[]
data
=
[]
check_invariant
(
heap
)
for
i
in
range
(
256
):
item
=
random
.
random
()
data
.
append
(
item
)
heappush
(
heap
,
item
)
check_invariant
(
heap
)
results
=
[]
while
heap
:
item
=
heappop
(
heap
)
check_invariant
(
heap
)
results
.
append
(
item
)
data_sorted
=
data
[:]
data_sorted
.
sort
()
vereq
(
data_sorted
,
results
)
# 2) Check that the invariant holds for a sorted array
check_invariant
(
results
)
# 3) Naive "N-best" algorithm
heap
=
[]
for
item
in
data
:
heappush
(
heap
,
item
)
if
len
(
heap
)
>
10
:
heappop
(
heap
)
heap
.
sort
()
vereq
(
heap
,
data_sorted
[
-
10
:])
# Make user happy
if
verbose
:
print
"All OK"
if
__name__
==
"__main__"
:
test_main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment