#NEWLINE# def test_genrandbits( self ) : #NEWLINE# #INDENT# for k in range ( 1 , 1000 ) : #NEWLINE# #INDENT# self . assertTrue ( ( 0 <= self . gen . getrandbits ( k ) < ( 2 ** k ) ) ) #NEWLINE# #UNINDENT# getbits = self . gen . getrandbits #NEWLINE# for span in [ 1 , 2 , 3 , 4 , 31 , 32 , 32 , 52 , 53 , 54 , 119 , 127 , 128 , 129 ] : #NEWLINE# #INDENT# cum = 0 #NEWLINE# for i in range ( 100 ) : #NEWLINE# #INDENT# cum |= getbits ( span ) #NEWLINE# #UNINDENT# self . assertEqual ( cum , ( ( 2 ** span ) - 1 ) ) #NEWLINE# #UNINDENT# self . assertRaises ( TypeError , self . gen . getrandbits ) #NEWLINE# self . assertRaises ( TypeError , self . gen . getrandbits , 1 , 2 ) #NEWLINE# self . assertRaises ( ValueError , self . gen . getrandbits , 0 ) #NEWLINE# self . assertRaises ( ValueError , self . gen . getrandbits , ( - 1 ) ) #NEWLINE# self . assertRaises ( TypeError , self . gen . getrandbits , 10.1 )