mirror of
https://github.com/python/cpython.git
synced 2026-01-07 16:02:55 +00:00
gh-135326: Test support of __index__ in random.getrandbits() (#135356)
This commit is contained in:
parent
0f866cbfef
commit
5ae669fc4e
1 changed files with 12 additions and 0 deletions
|
|
@ -14,6 +14,15 @@
|
|||
from fractions import Fraction
|
||||
from collections import abc, Counter
|
||||
|
||||
|
||||
class MyIndex:
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __index__(self):
|
||||
return self.value
|
||||
|
||||
|
||||
class TestBasicOps:
|
||||
# Superclass with tests common to all generators.
|
||||
# Subclasses must arrange for self.gen to retrieve the Random instance
|
||||
|
|
@ -809,6 +818,9 @@ def test_getrandbits(self):
|
|||
self.gen.seed(1234567)
|
||||
self.assertEqual(self.gen.getrandbits(100),
|
||||
97904845777343510404718956115)
|
||||
self.gen.seed(1234567)
|
||||
self.assertEqual(self.gen.getrandbits(MyIndex(100)),
|
||||
97904845777343510404718956115)
|
||||
|
||||
def test_getrandbits_2G_bits(self):
|
||||
size = 2**31
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue