diff options
| -rw-r--r-- | ms/ms.go | 11 | ||||
| -rw-r--r-- | ms/ms_test.go | 4 |
2 files changed, 10 insertions, 5 deletions
@@ -80,7 +80,7 @@ func (ma *MathematicalSeries[T]) AllSequentialIncreasesLessThan(limit float64) ( /* * N.B.: Overflow is possible -- use at your discretion! */ -func (ma *MathematicalSeries[T]) StandardDeviationLessThan(limit T) (bool, T) { +func (ma *MathematicalSeries[T]) StandardDeviation() (bool, T) { // If we have not yet accumulated a complete set of intervals, // we are always false. @@ -117,11 +117,16 @@ func (ma *MathematicalSeries[T]) StandardDeviationLessThan(limit T) (bool, T) { sd := T(math.Sqrt(variance)) //sd := T(variance) - return T(sd) < limit, sd + return true, sd } func (ma *MathematicalSeries[T]) IsNormallyDistributed() bool { - _, stddev := ma.StandardDeviationLessThan(0.0) + valid, stddev := ma.StandardDeviation() + // If there are not enough values in our series to generate a standard + // deviation, then we cannot do this calculation either. + if !valid { + return false + } avg := float64(ma.CalculateAverage()) fstddev := float64(stddev) diff --git a/ms/ms_test.go b/ms/ms_test.go index 86a5488..6f1e807 100644 --- a/ms/ms_test.go +++ b/ms/ms_test.go @@ -67,7 +67,7 @@ func Test_SequentialIncreasesAlwaysLessThanWithWraparoundInverse(test *testing.T } } -func Test_StandardDeviationLessThan_Float(test *testing.T) { +func Test_StandardDeviationCalculation(test *testing.T) { series := NewMathematicalSeries[float64](5) // 5.7, 1.0, 8.6, 7.4, 2.2 series.AddElement(5.7) @@ -76,7 +76,7 @@ func Test_StandardDeviationLessThan_Float(test *testing.T) { series.AddElement(7.4) series.AddElement(2.2) - if islt, sd := series.StandardDeviationLessThan(2.94); !islt { + if _, sd := series.StandardDeviation(); !utilities.ApproximatelyEqual(2.93, sd, 0.01) { test.Fatalf("Standard deviation max calculation failed: %v.", sd) } else { test.Logf("Standard deviation calculation result: %v", sd) |
