MCPcopy Index your code
hub / github.com/python/cpython / test_getrandbits

Method test_getrandbits

Lib/test/test_random.py:393–418  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

391 self.assertEqual(cum, span-1)
392
393 def test_getrandbits(self):
394 getrandbits = self.gen.getrandbits
395 # Verify ranges
396 for k in range(1, 1000):
397 self.assertTrue(0 <= getrandbits(k) < 2**k)
398 self.assertEqual(getrandbits(0), 0)
399
400 # Verify all bits active
401 for span in [1, 2, 3, 4, 31, 32, 32, 52, 53, 54, 119, 127, 128, 129]:
402 all_bits = 2**span-1
403 cum = 0
404 cpl_cum = 0
405 for i in range(100):
406 v = getrandbits(span)
407 cum |= v
408 cpl_cum |= all_bits ^ v
409 self.assertEqual(cum, all_bits)
410 self.assertEqual(cpl_cum, all_bits)
411
412 # Verify argument checking
413 self.assertRaises(TypeError, getrandbits)
414 self.assertRaises(TypeError, getrandbits, 1, 2)
415 self.assertRaises(ValueError, getrandbits, -1)
416 self.assertRaises(OverflowError, getrandbits, 1<<1000)
417 self.assertRaises(ValueError, getrandbits, -1<<1000)
418 self.assertRaises(TypeError, getrandbits, 10.1)
419
420 def test_bigrand(self):
421 # The randrange routine should build-up the required number of bits

Callers 1

test_getrandbitsMethod · 0.45

Calls 3

assertTrueMethod · 0.80
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected