added tests, proper inclusion of chisquared
Automatic style corrections courtesy of autopep8