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
a2dfc35a
Kaydet (Commit)
a2dfc35a
authored
Nis 12, 2013
tarafından
Andrew Svetlov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #13355: Raise ValueError on random.triangular call with invalid params.
Initial patch by Yuriy Senko.
üst
7b2c8bb8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
1 deletion
+45
-1
random.py
Lib/random.py
+10
-0
test_random.py
Lib/test/test_random.py
+31
-1
ACKS
Misc/ACKS
+1
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/random.py
Dosyayı görüntüle @
a2dfc35a
...
...
@@ -341,6 +341,16 @@ class Random(_random.Random):
http://en.wikipedia.org/wiki/Triangular_distribution
"""
# Sanity check. According to the doc low must be less or equal to
# high. And mode should be somewhere between these bounds.
if
low
>
high
:
raise
ValueError
(
'high cannot be less then low.'
)
if
mode
is
not
None
and
(
mode
<
low
or
mode
>
high
):
raise
ValueError
(
'mode must be between low and high.'
)
if
high
==
low
:
return
low
u
=
self
.
random
()
c
=
0.5
if
mode
is
None
else
(
mode
-
low
)
/
(
high
-
low
)
if
u
>
c
:
...
...
Lib/test/test_random.py
Dosyayı görüntüle @
a2dfc35a
...
...
@@ -46,6 +46,36 @@ class TestBasicOps(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
self
.
gen
.
seed
,
1
,
2
,
3
,
4
)
self
.
assertRaises
(
TypeError
,
type
(
self
.
gen
),
[])
def
test_triangular
(
self
):
# Check that triangular() correctly handles bad input. See issue 13355.
# mode > high.
with
self
.
assertRaises
(
ValueError
):
random
.
triangular
(
mode
=
2
)
with
self
.
assertRaises
(
ValueError
):
random
.
triangular
(
low
=
1
,
high
=
10
,
mode
=
11
)
with
self
.
assertRaises
(
ValueError
):
random
.
triangular
(
low
=
1
,
high
=
1
,
mode
=
11
)
# mode < low.
with
self
.
assertRaises
(
ValueError
):
random
.
triangular
(
mode
=-
1
)
with
self
.
assertRaises
(
ValueError
):
random
.
triangular
(
low
=
1
,
high
=
10
,
mode
=
0
)
with
self
.
assertRaises
(
ValueError
):
random
.
triangular
(
low
=
1
,
high
=
1
,
mode
=
0
)
# low > high
with
self
.
assertRaises
(
ValueError
):
random
.
triangular
(
low
=
5
,
high
=
2
)
with
self
.
assertRaises
(
ValueError
):
random
.
triangular
(
low
=
5
,
high
=
2
,
mode
=
1
)
with
self
.
assertRaises
(
ValueError
):
random
.
triangular
(
low
=-
2
,
high
=-
5
)
self
.
assertEqual
(
random
.
triangular
(
low
=
10
,
high
=
10
),
10
)
self
.
assertEqual
(
random
.
triangular
(
low
=
10
,
high
=
10
,
mode
=
10
),
10
)
def
test_choice
(
self
):
choice
=
self
.
gen
.
choice
with
self
.
assertRaises
(
IndexError
):
...
...
@@ -489,7 +519,7 @@ class TestDistributions(unittest.TestCase):
for
variate
,
args
,
expected
in
[
(
g
.
uniform
,
(
10.0
,
10.0
),
10.0
),
(
g
.
triangular
,
(
10.0
,
10.0
),
10.0
),
#
(g.triangular, (10.0, 10.0, 10.0), 10.0),
(
g
.
triangular
,
(
10.0
,
10.0
,
10.0
),
10.0
),
(
g
.
expovariate
,
(
float
(
'inf'
),),
0.0
),
(
g
.
vonmisesvariate
,
(
3.0
,
float
(
'inf'
)),
3.0
),
(
g
.
gauss
,
(
10.0
,
0.0
),
10.0
),
...
...
Misc/ACKS
Dosyayı görüntüle @
a2dfc35a
...
...
@@ -1088,6 +1088,7 @@ Nick Seidenman
Žiga Seilnacht
Yury Selivanov
Fred Sells
Yuriy Senko
Jiwon Seo
Iñigo Serna
Joakim Sernbrant
...
...
Misc/NEWS
Dosyayı görüntüle @
a2dfc35a
...
...
@@ -23,6 +23,9 @@ Core and Builtins
Library
-------
-
Issue
#
13355
:
Raise
ValueError
on
random
.
triangular
call
with
invalid
params
.
Initial
patch
by
Yuriy
Senko
.
-
Issue
#
16658
:
add
missing
return
to
HTTPConnection
.
send
()
Patch
by
Jeff
Knupp
.
...
...
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