MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_avg_std

Method test_avg_std

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

Source from the content-addressed store, hash-verified

1043 g.random = x[:].pop; g.triangular(0.0, 1.0, 1.0/3.0)
1044
1045 def test_avg_std(self):
1046 # Use integration to test distribution average and standard deviation.
1047 # Only works for distributions which do not consume variates in pairs
1048 g = random.Random()
1049 N = 5000
1050 x = [i/float(N) for i in range(1,N)]
1051 for variate, args, mu, sigmasqrd in [
1052 (g.uniform, (1.0,10.0), (10.0+1.0)/2, (10.0-1.0)**2/12),
1053 (g.triangular, (0.0, 1.0, 1.0/3.0), 4.0/9.0, 7.0/9.0/18.0),
1054 (g.expovariate, (1.5,), 1/1.5, 1/1.5**2),
1055 (g.vonmisesvariate, (1.23, 0), pi, pi**2/3),
1056 (g.paretovariate, (5.0,), 5.0/(5.0-1),
1057 5.0/((5.0-1)**2*(5.0-2))),
1058 (g.weibullvariate, (1.0, 3.0), gamma(1+1/3.0),
1059 gamma(1+2/3.0)-gamma(1+1/3.0)**2) ]:
1060 g.random = x[:].pop
1061 y = []
1062 for i in range(len(x)):
1063 try:
1064 y.append(variate(*args))
1065 except IndexError:
1066 pass
1067 s1 = s2 = 0
1068 for e in y:
1069 s1 += e
1070 s2 += (e - mu) ** 2
1071 N = len(y)
1072 self.assertAlmostEqual(s1/N, mu, places=2,
1073 msg='%s%r' % (variate.__name__, args))
1074 self.assertAlmostEqual(s2/(N-1), sigmasqrd, places=2,
1075 msg='%s%r' % (variate.__name__, args))
1076
1077 def test_constant(self):
1078 g = random.Random()

Callers

nothing calls this directly

Calls 4

lenFunction · 0.85
gammaFunction · 0.70
appendMethod · 0.45
assertAlmostEqualMethod · 0.45

Tested by

no test coverage detected