stat/distuv: complete test coverage for ChiSquared

Fix Mode function.
This commit is contained in:
Roman Werpachowski
2020-06-02 00:22:12 +01:00
committed by GitHub
parent 9357fac8d2
commit 82a2149e32
2 changed files with 20 additions and 1 deletions

View File

@@ -55,7 +55,7 @@ func (c ChiSquared) Mean() float64 {
// Mode returns the mode of the distribution.
func (c ChiSquared) Mode() float64 {
return math.Min(c.K-2, 0)
return math.Max(c.K-2, 0)
}
// NumParameters returns the number of parameters in the distribution.

View File

@@ -5,6 +5,7 @@
package distuv
import (
"math"
"sort"
"testing"
@@ -81,4 +82,22 @@ func testChiSquared(t *testing.T, c ChiSquared, i int) {
checkExKurtosis(t, i, x, c, 7e-2)
checkProbContinuous(t, i, x, c, 1e-3)
checkQuantileCDFSurvival(t, i, x, c, 1e-2)
expectedMode := math.Max(c.K-2, 0)
if c.Mode() != expectedMode {
t.Errorf("Mode is not equal to max(k - 2, 0). Got %v, want %v", c.Mode(), expectedMode)
}
if c.NumParameters() != 1 {
t.Errorf("NumParameters is not 1. Got %v", c.NumParameters())
}
if !panics(func() { c.Quantile(-0.0001) }) {
t.Errorf("Expected panic with negative argument to Quantile")
}
if !panics(func() { c.Quantile(1.0001) }) {
t.Errorf("Expected panic with argument to Quantile above 1")
}
survival := c.Survival(-0.00001)
if survival != 1 {
t.Errorf("Survival is not 1 for negative argument. Got %v", survival)
}
}