Skip to content

Commit 278c11b

Browse files
authored
Add 'Test' for gh-149422
# Test for gh-149222: binomialvariate should not crash when random()
1 parent c063df9 commit 278c11b

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Lib/test/test_random.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,13 @@ def test_avg_std(self):
10751075
msg='%s%r' % (variate.__name__, args))
10761076
self.assertAlmostEqual(s2/(N-1), sigmasqrd, places=2,
10771077
msg='%s%r' % (variate.__name__, args))
1078+
1079+
@unittest.mock.patch.object(random.Random, 'random', return_value=0.0)
1080+
def test_binomialvariate_log_zero(self, mock_random):
1081+
# Test for gh-149222: binomialvariate should not crash when random()
1082+
result = random.binomialvariate(10, 0.5)
1083+
self.assertIsInstance(result, int)
1084+
self.assertIn(result, range(11))
10781085

10791086
def test_constant(self):
10801087
g = random.Random()

0 commit comments

Comments
 (0)