cpython: e948154af406 (original) (raw)
--- a/Lib/random.py +++ b/Lib/random.py @@ -341,16 +341,6 @@ class Random(_random.Random): http://en.wikipedia.org/wiki/Triangular_distribution[](#l1.4) """
# Sanity check. According to the doc low must be less or equal to[](#l1.7)
# high. And mode should be somewhere between these bounds.[](#l1.8)
if low > high:[](#l1.9)
raise ValueError('high cannot be less then low.')[](#l1.10)
if mode is not None and (mode < low or mode > high):[](#l1.11)
raise ValueError('mode must be between low and high.')[](#l1.12)
if high == low:[](#l1.14)
return low[](#l1.15)
- u = self.random() c = 0.5 if mode is None else (mode - low) / (high - low) if u > c:
--- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -46,36 +46,6 @@ 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.[](#l2.8)
# mode > high.[](#l2.10)
with self.assertRaises(ValueError):[](#l2.11)
random.triangular(mode=2)[](#l2.12)
with self.assertRaises(ValueError):[](#l2.13)
random.triangular(low=1, high=10, mode=11)[](#l2.14)
with self.assertRaises(ValueError):[](#l2.15)
random.triangular(low=1, high=1, mode=11)[](#l2.16)
# mode < low.[](#l2.18)
with self.assertRaises(ValueError):[](#l2.19)
random.triangular(mode=-1)[](#l2.20)
with self.assertRaises(ValueError):[](#l2.21)
random.triangular(low=1, high=10, mode=0)[](#l2.22)
with self.assertRaises(ValueError):[](#l2.23)
random.triangular(low=1, high=1, mode=0)[](#l2.24)
# low > high[](#l2.26)
with self.assertRaises(ValueError):[](#l2.27)
random.triangular(low=5, high=2)[](#l2.28)
with self.assertRaises(ValueError):[](#l2.29)
random.triangular(low=5, high=2, mode=1)[](#l2.30)
with self.assertRaises(ValueError):[](#l2.31)
random.triangular(low=-2, high=-5)[](#l2.32)
self.assertEqual(random.triangular(low=10, high=10), 10)[](#l2.34)
self.assertEqual(random.triangular(low=10, high=10, mode=10), 10)[](#l2.35)
- def test_choice(self): choice = self.gen.choice with self.assertRaises(IndexError): @@ -519,7 +489,7 @@ class TestDistributions(unittest.TestCas 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),[](#l2.44)
#(g.triangular, (10.0, 10.0, 10.0), 10.0),[](#l2.45) (g.expovariate, (float('inf'),), 0.0),[](#l2.46) (g.vonmisesvariate, (3.0, float('inf')), 3.0),[](#l2.47) (g.gauss, (10.0, 0.0), 10.0),[](#l2.48)
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -1088,7 +1088,6 @@ Nick Seidenman Žiga Seilnacht Yury Selivanov Fred Sells -Yuriy Senko Jiwon Seo Iñigo Serna Joakim Sernbrant
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -26,9 +26,6 @@ Core and Builtins Library ------- -- Issue #13355: Raise ValueError on random.triangular call with invalid params.