#NEWLINE# def test_avg_std( self ) : #NEWLINE# #INDENT# g = random . Random ( ) #NEWLINE# N = 5000 #NEWLINE# x = [ ( i / float ( N ) ) for i in range ( 1 , N ) ] #NEWLINE# for ( variate , args , mu , sigmasqrd ) in [ ( g . uniform , ( 1.0 , 10.0 ) , ( ( 10.0 + 1.0 ) / 2 ) , ( ( ( 10.0 - 1.0 ) ** 2 ) / 12 ) ) , ( g . triangular , ( 0.0 , 1.0 , ( 1.0 / 3.0 ) ) , ( 4.0 / 9.0 ) , ( ( 7.0 / 9.0 ) / 18.0 ) ) , ( g . expovariate , ( 1.5 , ) , ( 1 / 1.5 ) , ( 1 / ( 1.5 ** 2 ) ) ) , ( g . vonmisesvariate , ( 1.23 , 0 ) , pi , ( ( pi ** 2 ) / 3 ) ) , ( g . paretovariate , ( 5.0 , ) , ( 5.0 / ( 5.0 - 1 ) ) , ( 5.0 / ( ( ( 5.0 - 1 ) ** 2 ) * ( 5.0 - 2 ) ) ) ) , ( g . weibullvariate , ( 1.0 , 3.0 ) , gamma ( ( 1 + ( 1 / 3.0 ) ) ) , ( gamma ( ( 1 + ( 2 / 3.0 ) ) ) - ( gamma ( ( 1 + ( 1 / 3.0 ) ) ) ** 2 ) ) ) ] : #NEWLINE# #INDENT# g . random = x [ : ] . pop #NEWLINE# y = [ ] #NEWLINE# for i in range ( len ( x ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# y . append ( variate ( * args ) ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# s1 = s2 = 0 #NEWLINE# for e in y : #NEWLINE# #INDENT# s1 += e #NEWLINE# s2 += ( ( e - mu ) ** 2 ) #NEWLINE# #UNINDENT# N = len ( y ) #NEWLINE# self . assertAlmostEqual ( ( s1 / N ) , mu , places = 2 , msg = ( '%s%r' % ( variate . __name__ , args ) ) ) #NEWLINE# self . assertAlmostEqual ( ( s2 / ( N - 1 ) ) , sigmasqrd , places = 2 , msg = ( '%s%r' % ( variate . __name__ , args ) ) )