Chi2 test does not always return the chi2 value

When a data point is out of support, the chi2 statistical test
does not return the chi2 statistic value.

This pull-request fixes it and adds corresponding unit tests.