Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4fd468

Browse files
committed
Revert changes for #13355 by request from Raymond Hettinger
1 parent 64aafeb commit b4fd468

4 files changed

Lines changed: 1 addition & 45 deletions

File tree

Lib/random.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,16 +341,6 @@ def triangular(self, low=0.0, high=1.0, mode=None):
341341
http://en.wikipedia.org/wiki/Triangular_distribution
342342
343343
"""
344-
# Sanity check. According to the doc low must be less or equal to
345-
# high. And mode should be somewhere between these bounds.
346-
if low > high:
347-
raise ValueError('high cannot be less then low.')
348-
if mode is not None and (mode < low or mode > high):
349-
raise ValueError('mode must be between low and high.')
350-
351-
if high == low:
352-
return low
353-
354344
u = self.random()
355345
c = 0.5 if mode is None else (mode - low) / (high - low)
356346
if u > c:

Lib/test/test_random.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,36 +46,6 @@ def __hash__(self):
4646
self.assertRaises(TypeError, self.gen.seed, 1, 2, 3, 4)
4747
self.assertRaises(TypeError, type(self.gen), [])
4848

49-
def test_triangular(self):
50-
# Check that triangular() correctly handles bad input. See issue 13355.
51-
52-
# mode > high.
53-
with self.assertRaises(ValueError):
54-
random.triangular(mode=2)
55-
with self.assertRaises(ValueError):
56-
random.triangular(low=1, high=10, mode=11)
57-
with self.assertRaises(ValueError):
58-
random.triangular(low=1, high=1, mode=11)
59-
60-
# mode < low.
61-
with self.assertRaises(ValueError):
62-
random.triangular(mode=-1)
63-
with self.assertRaises(ValueError):
64-
random.triangular(low=1, high=10, mode=0)
65-
with self.assertRaises(ValueError):
66-
random.triangular(low=1, high=1, mode=0)
67-
68-
# low > high
69-
with self.assertRaises(ValueError):
70-
random.triangular(low=5, high=2)
71-
with self.assertRaises(ValueError):
72-
random.triangular(low=5, high=2, mode=1)
73-
with self.assertRaises(ValueError):
74-
random.triangular(low=-2, high=-5)
75-
76-
self.assertEqual(random.triangular(low=10, high=10), 10)
77-
self.assertEqual(random.triangular(low=10, high=10, mode=10), 10)
78-
7949
def test_choice(self):
8050
choice = self.gen.choice
8151
with self.assertRaises(IndexError):
@@ -519,7 +489,7 @@ def test_constant(self):
519489
for variate, args, expected in [
520490
(g.uniform, (10.0, 10.0), 10.0),
521491
(g.triangular, (10.0, 10.0), 10.0),
522-
(g.triangular, (10.0, 10.0, 10.0), 10.0),
492+
#(g.triangular, (10.0, 10.0, 10.0), 10.0),
523493
(g.expovariate, (float('inf'),), 0.0),
524494
(g.vonmisesvariate, (3.0, float('inf')), 3.0),
525495
(g.gauss, (10.0, 0.0), 10.0),

Misc/ACKS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,6 @@ Nick Seidenman
10881088
Žiga Seilnacht
10891089
Yury Selivanov
10901090
Fred Sells
1091-
Yuriy Senko
10921091
Jiwon Seo
10931092
Iñigo Serna
10941093
Joakim Sernbrant

Misc/NEWS

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ Core and Builtins
2626
Library
2727
-------
2828

29-
- Issue #13355: Raise ValueError on random.triangular call with invalid params.
30-
Initial patch by Yuriy Senko.
31-
3229
- Issue #16658: add missing return to HTTPConnection.send()
3330
Patch by Jeff Knupp.
3431

0 commit comments

Comments
 (0)