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
5e394331
Kaydet (Commit)
5e394331
authored
Kas 04, 2012
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #15837: add some tests for random.shuffle().
Patch by Alessandro Moura.
üst
e9d08cf4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
+37
-3
random.py
Lib/random.py
+4
-3
test_random.py
Lib/test/test_random.py
+33
-0
No files found.
Lib/random.py
Dosyayı görüntüle @
5e394331
...
...
@@ -252,10 +252,11 @@ class Random(_random.Random):
return
seq
[
i
]
def
shuffle
(
self
,
x
,
random
=
None
,
int
=
int
):
"""
x, random=random.random -> shuffle list x in place;
return None.
"""
Shuffle list x in place, and
return None.
Optional arg random is a 0-argument function returning a random
float in [0.0, 1.0); by default, the standard random.random.
Optional argument random is a 0-argument function returning a
random float in [0.0, 1.0); if it is the default None, the
standard random.random will be used.
"""
randbelow
=
self
.
_randbelow
...
...
Lib/test/test_random.py
Dosyayı görüntüle @
5e394331
...
...
@@ -46,6 +46,39 @@ class TestBasicOps(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
self
.
gen
.
seed
,
1
,
2
,
3
,
4
)
self
.
assertRaises
(
TypeError
,
type
(
self
.
gen
),
[])
def
test_shuffle
(
self
):
shuffle
=
self
.
gen
.
shuffle
lst
=
[]
shuffle
(
lst
)
self
.
assertEqual
(
lst
,
[])
lst
=
[
37
]
shuffle
(
lst
)
self
.
assertEqual
(
lst
,
[
37
])
seqs
=
[
list
(
range
(
n
))
for
n
in
range
(
10
)]
shuffled_seqs
=
[
list
(
range
(
n
))
for
n
in
range
(
10
)]
for
shuffled_seq
in
shuffled_seqs
:
shuffle
(
shuffled_seq
)
for
(
seq
,
shuffled_seq
)
in
zip
(
seqs
,
shuffled_seqs
):
self
.
assertEqual
(
len
(
seq
),
len
(
shuffled_seq
))
self
.
assertEqual
(
set
(
seq
),
set
(
shuffled_seq
))
# The above tests all would pass if the shuffle was a
# no-op. The following non-deterministic test covers that. It
# asserts that the shuffled sequence of 1000 distinct elements
# must be different from the original one. Although there is
# mathematically a non-zero probability that this could
# actually happen in a genuinely random shuffle, it is
# completely negligible, given that the number of possible
# permutations of 1000 objects is 1000! (factorial of 1000),
# which is considerably larger than the number of atoms in the
# universe...
lst
=
list
(
range
(
1000
))
shuffled_lst
=
list
(
range
(
1000
))
shuffle
(
shuffled_lst
)
self
.
assertTrue
(
lst
!=
shuffled_lst
)
shuffle
(
lst
)
self
.
assertTrue
(
lst
!=
shuffled_lst
)
def
test_choice
(
self
):
choice
=
self
.
gen
.
choice
with
self
.
assertRaises
(
IndexError
):
...
...
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