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
5833587d
Kaydet (Commit)
5833587d
authored
Tem 09, 2004
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add some tests for corner cases.
üst
d87ac8f2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
1 deletion
+25
-1
test_random.py
Lib/test/test_random.py
+25
-1
No files found.
Lib/test/test_random.py
Dosyayı görüntüle @
5833587d
...
@@ -39,6 +39,8 @@ class TestBasicOps(unittest.TestCase):
...
@@ -39,6 +39,8 @@ class TestBasicOps(unittest.TestCase):
self
.
gen
.
seed
(
arg
)
self
.
gen
.
seed
(
arg
)
for
arg
in
[
range
(
3
),
dict
(
one
=
1
)]:
for
arg
in
[
range
(
3
),
dict
(
one
=
1
)]:
self
.
assertRaises
(
TypeError
,
self
.
gen
.
seed
,
arg
)
self
.
assertRaises
(
TypeError
,
self
.
gen
.
seed
,
arg
)
self
.
assertRaises
(
TypeError
,
self
.
gen
.
seed
,
1
,
2
)
self
.
assertRaises
(
TypeError
,
type
(
self
.
gen
),
[])
def
test_jumpahead
(
self
):
def
test_jumpahead
(
self
):
self
.
gen
.
seed
()
self
.
gen
.
seed
()
...
@@ -122,6 +124,9 @@ class TestBasicOps(unittest.TestCase):
...
@@ -122,6 +124,9 @@ class TestBasicOps(unittest.TestCase):
class
WichmannHill_TestBasicOps
(
TestBasicOps
):
class
WichmannHill_TestBasicOps
(
TestBasicOps
):
gen
=
random
.
WichmannHill
()
gen
=
random
.
WichmannHill
()
def
test_setstate_first_arg
(
self
):
self
.
assertRaises
(
ValueError
,
self
.
gen
.
setstate
,
(
2
,
None
,
None
))
def
test_strong_jumpahead
(
self
):
def
test_strong_jumpahead
(
self
):
# tests that jumpahead(n) semantics correspond to n calls to random()
# tests that jumpahead(n) semantics correspond to n calls to random()
N
=
1000
N
=
1000
...
@@ -162,6 +167,19 @@ class WichmannHill_TestBasicOps(TestBasicOps):
...
@@ -162,6 +167,19 @@ class WichmannHill_TestBasicOps(TestBasicOps):
class
MersenneTwister_TestBasicOps
(
TestBasicOps
):
class
MersenneTwister_TestBasicOps
(
TestBasicOps
):
gen
=
random
.
Random
()
gen
=
random
.
Random
()
def
test_setstate_first_arg
(
self
):
self
.
assertRaises
(
ValueError
,
self
.
gen
.
setstate
,
(
1
,
None
,
None
))
def
test_setstate_middle_arg
(
self
):
# Wrong type, s/b tuple
self
.
assertRaises
(
TypeError
,
self
.
gen
.
setstate
,
(
2
,
None
,
None
))
# Wrong length, s/b 625
self
.
assertRaises
(
ValueError
,
self
.
gen
.
setstate
,
(
2
,
(
1
,
2
,
3
),
None
))
# Wrong type, s/b tuple of 625 ints
self
.
assertRaises
(
TypeError
,
self
.
gen
.
setstate
,
(
2
,
(
'a'
,)
*
625
,
None
))
# Last element s/b an int also
self
.
assertRaises
(
TypeError
,
self
.
gen
.
setstate
,
(
2
,
(
0
,)
*
624
+
(
'a'
,),
None
))
def
test_referenceImplementation
(
self
):
def
test_referenceImplementation
(
self
):
# Compare the python implementation with results from the original
# Compare the python implementation with results from the original
# code. Create 2000 53-bit precision random floats. Compare only
# code. Create 2000 53-bit precision random floats. Compare only
...
@@ -210,7 +228,6 @@ class MersenneTwister_TestBasicOps(TestBasicOps):
...
@@ -210,7 +228,6 @@ class MersenneTwister_TestBasicOps(TestBasicOps):
0x11388382c15694
L
,
0x11388382c15694
L
,
0x02dad977c9e1fe
L
,
0x02dad977c9e1fe
L
,
0x191d96d4d334c6
L
]
0x191d96d4d334c6
L
]
self
.
gen
.
seed
(
61731L
+
(
24903L
<<
32
)
+
(
614L
<<
64
)
+
(
42143L
<<
96
))
self
.
gen
.
seed
(
61731L
+
(
24903L
<<
32
)
+
(
614L
<<
64
)
+
(
42143L
<<
96
))
actual
=
self
.
randomlist
(
2000
)[
-
10
:]
actual
=
self
.
randomlist
(
2000
)[
-
10
:]
for
a
,
e
in
zip
(
actual
,
expected
):
for
a
,
e
in
zip
(
actual
,
expected
):
...
@@ -274,6 +291,13 @@ class MersenneTwister_TestBasicOps(TestBasicOps):
...
@@ -274,6 +291,13 @@ class MersenneTwister_TestBasicOps(TestBasicOps):
cum
|=
getbits
(
span
)
cum
|=
getbits
(
span
)
self
.
assertEqual
(
cum
,
2
**
span
-
1
)
self
.
assertEqual
(
cum
,
2
**
span
-
1
)
# Verify argument checking
self
.
assertRaises
(
TypeError
,
self
.
gen
.
getrandbits
)
self
.
assertRaises
(
TypeError
,
self
.
gen
.
getrandbits
,
'a'
)
self
.
assertRaises
(
TypeError
,
self
.
gen
.
getrandbits
,
1
,
2
)
self
.
assertRaises
(
ValueError
,
self
.
gen
.
getrandbits
,
0
)
self
.
assertRaises
(
ValueError
,
self
.
gen
.
getrandbits
,
-
1
)
def
test_randbelow_logic
(
self
,
_log
=
log
,
int
=
int
):
def
test_randbelow_logic
(
self
,
_log
=
log
,
int
=
int
):
# check bitcount transition points: 2**i and 2**(i+1)-1
# check bitcount transition points: 2**i and 2**(i+1)-1
# show that: k = int(1.001 + _log(n, 2))
# show that: k = int(1.001 + _log(n, 2))
...
...
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