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
a98e7694
Kaydet (Commit)
a98e7694
authored
Kas 24, 2005
tarafından
Neal Norwitz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
move test into a unittest.TestCase, no functional changes
üst
f06e30af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
74 deletions
+74
-74
test_sort.py
Lib/test/test_sort.py
+74
-74
No files found.
Lib/test/test_sort.py
Dosyayı görüntüle @
a98e7694
from
test
.test_support
import
verbose
from
test
import
test_support
import
random
from
UserList
import
UserList
import
sys
import
unittest
verbose
=
test_support
.
verbose
nerrors
=
0
def
check
(
tag
,
expected
,
raw
,
compare
=
None
):
...
...
@@ -36,91 +38,88 @@ def check(tag, expected, raw, compare=None):
nerrors
+=
1
return
# Try a variety of sizes at and around powers of 2, and at powers of 10.
sizes
=
[
0
]
for
power
in
range
(
1
,
10
):
n
=
2
**
power
sizes
.
extend
(
range
(
n
-
1
,
n
+
2
))
sizes
.
extend
([
10
,
100
,
1000
])
class
Complains
(
object
):
maybe_complain
=
True
class
TestBase
(
unittest
.
TestCase
):
def
testStressfully
(
self
):
# Try a variety of sizes at and around powers of 2, and at powers of 10.
sizes
=
[
0
]
for
power
in
range
(
1
,
10
):
n
=
2
**
power
sizes
.
extend
(
range
(
n
-
1
,
n
+
2
))
sizes
.
extend
([
10
,
100
,
1000
])
def
__init__
(
self
,
i
):
self
.
i
=
i
class
Complains
(
object
):
maybe_complain
=
True
def
__lt__
(
self
,
other
):
if
Complains
.
maybe_complain
and
random
.
random
()
<
0.001
:
if
verbose
:
print
" complaining at"
,
self
,
other
raise
RuntimeError
return
self
.
i
<
other
.
i
def
__init__
(
self
,
i
):
self
.
i
=
i
def
__repr__
(
self
):
return
"Complains(
%
d)"
%
self
.
i
def
__lt__
(
self
,
other
):
if
Complains
.
maybe_complain
and
random
.
random
()
<
0.001
:
if
verbose
:
print
" complaining at"
,
self
,
other
raise
RuntimeError
return
self
.
i
<
other
.
i
class
Stable
(
object
):
def
__init__
(
self
,
key
,
i
):
self
.
key
=
key
self
.
index
=
i
def
__repr__
(
self
):
return
"Complains(
%
d)"
%
self
.
i
def
__cmp__
(
self
,
other
):
return
cmp
(
self
.
key
,
other
.
key
)
class
Stable
(
object
):
def
__init__
(
self
,
key
,
i
):
self
.
key
=
key
self
.
index
=
i
def
__repr__
(
self
):
return
"Stable(
%
d,
%
d)"
%
(
self
.
key
,
self
.
index
)
def
__cmp__
(
self
,
other
):
return
cmp
(
self
.
key
,
other
.
key
)
for
n
in
sizes
:
x
=
range
(
n
)
if
verbose
:
print
"Testing size"
,
n
def
__repr__
(
self
):
return
"Stable(
%
d,
%
d)"
%
(
self
.
key
,
self
.
index
)
s
=
x
[:]
check
(
"identity"
,
x
,
s
)
s
=
x
[:]
s
.
reverse
()
check
(
"reversed"
,
x
,
s
)
for
n
in
sizes
:
x
=
range
(
n
)
if
verbose
:
print
"Testing size"
,
n
s
=
x
[:]
random
.
shuffle
(
s
)
check
(
"random permutation"
,
x
,
s
)
s
=
x
[:]
check
(
"identity"
,
x
,
s
)
y
=
x
[:]
y
.
reverse
()
s
=
x
[:]
check
(
"reversed via function"
,
y
,
s
,
lambda
a
,
b
:
cmp
(
b
,
a
))
s
=
x
[:]
s
.
reverse
()
check
(
"reversed"
,
x
,
s
)
if
verbose
:
print
" Checking against an insane comparison function."
print
" If the implementation isn't careful, this may segfault."
s
=
x
[:]
s
.
sort
(
lambda
a
,
b
:
int
(
random
.
random
()
*
3
)
-
1
)
check
(
"an insane function left some permutation"
,
x
,
s
)
x
=
[
Complains
(
i
)
for
i
in
x
]
s
=
x
[:]
random
.
shuffle
(
s
)
Complains
.
maybe_complain
=
True
it_complained
=
False
try
:
s
.
sort
()
except
RuntimeError
:
it_complained
=
True
if
it_complained
:
Complains
.
maybe_complain
=
False
check
(
"exception during sort left some permutation"
,
x
,
s
)
s
=
[
Stable
(
random
.
randrange
(
10
),
i
)
for
i
in
xrange
(
n
)]
augmented
=
[(
e
,
e
.
index
)
for
e
in
s
]
augmented
.
sort
()
# forced stable because ties broken by index
x
=
[
e
for
e
,
i
in
augmented
]
# a stable sort of s
check
(
"stability"
,
x
,
s
)
s
=
x
[:]
random
.
shuffle
(
s
)
check
(
"random permutation"
,
x
,
s
)
y
=
x
[:]
y
.
reverse
()
s
=
x
[:]
check
(
"reversed via function"
,
y
,
s
,
lambda
a
,
b
:
cmp
(
b
,
a
))
import
unittest
from
test
import
test_support
import
sys
if
verbose
:
print
" Checking against an insane comparison function."
print
" If the implementation isn't careful, this may segfault."
s
=
x
[:]
s
.
sort
(
lambda
a
,
b
:
int
(
random
.
random
()
*
3
)
-
1
)
check
(
"an insane function left some permutation"
,
x
,
s
)
x
=
[
Complains
(
i
)
for
i
in
x
]
s
=
x
[:]
random
.
shuffle
(
s
)
Complains
.
maybe_complain
=
True
it_complained
=
False
try
:
s
.
sort
()
except
RuntimeError
:
it_complained
=
True
if
it_complained
:
Complains
.
maybe_complain
=
False
check
(
"exception during sort left some permutation"
,
x
,
s
)
s
=
[
Stable
(
random
.
randrange
(
10
),
i
)
for
i
in
xrange
(
n
)]
augmented
=
[(
e
,
e
.
index
)
for
e
in
s
]
augmented
.
sort
()
# forced stable because ties broken by index
x
=
[
e
for
e
,
i
in
augmented
]
# a stable sort of s
check
(
"stability"
,
x
,
s
)
#==============================================================================
...
...
@@ -269,6 +268,7 @@ class TestDecorateSortUndecorate(unittest.TestCase):
def
test_main
(
verbose
=
None
):
test_classes
=
(
TestBase
,
TestDecorateSortUndecorate
,
TestBugs
,
)
...
...
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