mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
bpo-42222: Modernize integer test/conversion in randrange() (#23064)
This commit is contained in:
parent
1031f23fc3
commit
a9621bb301
4 changed files with 81 additions and 11 deletions
|
@ -542,6 +542,26 @@ class SystemRandom_TestBasicOps(TestBasicOps, unittest.TestCase):
|
|||
raises(0, 42, 0)
|
||||
raises(0, 42, 3.14159)
|
||||
|
||||
def test_randrange_argument_handling(self):
|
||||
randrange = self.gen.randrange
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
randrange(10.0, 20, 2)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
randrange(10, 20.0, 2)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
randrange(10, 20, 1.0)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
randrange(10, 20, 2.0)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with self.assertRaises(ValueError):
|
||||
randrange(10.5)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with self.assertRaises(ValueError):
|
||||
randrange(10, 20.5)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with self.assertRaises(ValueError):
|
||||
randrange(10, 20, 1.5)
|
||||
|
||||
def test_randbelow_logic(self, _log=log, int=int):
|
||||
# check bitcount transition points: 2**i and 2**(i+1)-1
|
||||
# show that: k = int(1.001 + _log(n, 2))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue