#NEWLINE# def test_using_weights( self ) : #NEWLINE# #INDENT# def take( generator , count ) : #NEWLINE# #INDENT# return list ( itertools . islice ( generator , 0 , count ) ) #NEWLINE# #UNINDENT# data = take ( take_using_weights ( [ 'A' , 'B' , 'C' ] , [ 5 , 10 , 20 ] ) , 35 ) #NEWLINE# self . assertEqual ( data . count ( 'A' ) , 5 ) #NEWLINE# self . assertEqual ( data . count ( 'B' ) , 10 ) #NEWLINE# self . assertEqual ( data . count ( 'C' ) , 20 ) #NEWLINE# self . assertEqual ( data , [ 'A' , 'B' , 'C' , 'C' , 'B' , 'C' , 'C' , 'A' , 'B' , 'C' , 'C' , 'B' , 'C' , 'C' , 'A' , 'B' , 'C' , 'C' , 'B' , 'C' , 'C' , 'A' , 'B' , 'C' , 'C' , 'B' , 'C' , 'C' , 'A' , 'B' , 'C' , 'C' , 'B' , 'C' , 'C' ] ) #NEWLINE# data = take ( take_using_weights ( [ 'A' , 'B' , 'C' ] , [ 20 , 10 , 5 ] ) , 35 ) #NEWLINE# self . assertEqual ( data . count ( 'A' ) , 20 ) #NEWLINE# self . assertEqual ( data . count ( 'B' ) , 10 ) #NEWLINE# self . assertEqual ( data . count ( 'C' ) , 5 ) #NEWLINE# data = take ( take_using_weights ( [ 'A' , 'B' , 'C' ] , [ 20 , 10 , 5 ] ) , 70 ) #NEWLINE# self . assertEqual ( data . count ( 'A' ) , 40 ) #NEWLINE# self . assertEqual ( data . count ( 'B' ) , 20 ) #NEWLINE# self . assertEqual ( data . count ( 'C' ) , 10 ) #NEWLINE# data = take ( take_using_weights ( [ 'A' , 'B' , 'C' ] , [ ( - 20 ) , 10 , 0 ] ) , 70 ) #NEWLINE# self . assertEqual ( data . count ( 'A' ) , 0 ) #NEWLINE# self . assertEqual ( data . count ( 'B' ) , 70 ) #NEWLINE# self . assertEqual ( data . count ( 'C' ) , 0 )