test_statsutils.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. # -*- coding: utf-8 -*-
  2. from boltons.statsutils import Stats
  3. def test_stats_basic():
  4. da = Stats(range(20))
  5. assert da.mean == 9.5
  6. assert round(da.std_dev, 2) == 5.77
  7. assert da.variance == 33.25
  8. assert da.skewness == 0
  9. assert round(da.kurtosis, 1) == 1.9
  10. assert da.median == 9.5
  11. def _test_pearson():
  12. import random
  13. from statsutils import pearson_type
  14. def get_pt(dist):
  15. vals = [dist() for x in range(10000)]
  16. pt = pearson_type(vals)
  17. return pt
  18. for x in range(3):
  19. # pt = get_pt(dist=lambda: random.normalvariate(15, 5)) # expect 0, normal
  20. # pt = get_pt(dist=lambda: random.weibullvariate(2, 3)) # gets 1, beta, weibull not specifically supported
  21. # pt = get_pt(dist=lambda: random.gammavariate(2, 3)) # expect 3, gamma
  22. # pt = get_pt(dist=lambda: random.betavariate(2, 3)) # expect 1, beta
  23. # pt = get_pt(dist=lambda: random.expovariate(0.2)) # expect 3, beta
  24. pt = get_pt(dist=lambda: random.uniform(0.0, 10.0)) # gets 2
  25. print('pearson type:', pt)
  26. # import pdb;pdb.set_trace()