Skip to content

Commit

Permalink
In the new test, allow random changes to the bit length
Browse files Browse the repository at this point in the history
to be negative too, and check that the result string doesn't
start with a zero.
  • Loading branch information
tim-one committed May 7, 2024
1 parent 5f9cd7a commit f5b410f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Lib/test/test_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,13 @@ def test_pylong_roundtrip(self):
from random import randrange
bits = 5000
while bits <= 1_000_000:
bits += randrange(100) # break bitlength patterns
bits += randrange(-100, 101) # break bitlength patterns
hibit = 1 << (bits - 1)
n = hibit + randrange(hibit)
assert n.bit_length() == bits
self.assertEqual(n, int(str(n)))
sn = str(n)
self.assertFalse(sn.startswith('0'))
self.assertEqual(n, int(sn))
bits <<= 1

if __name__ == "__main__":
Expand Down

0 comments on commit f5b410f

Please sign in to comment.