summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ms/ms.go22
-rw-r--r--ms/ms_test.go18
2 files changed, 40 insertions, 0 deletions
diff --git a/ms/ms.go b/ms/ms.go
index 8214025..da2d201 100644
--- a/ms/ms.go
+++ b/ms/ms.go
@@ -77,6 +77,9 @@ func (ma *MathematicalSeries[T]) AllSequentialIncreasesLessThan(limit float64) (
return true, maximumSequentialIncrease
}
+/*
+ * N.B.: Overflow is possible -- use at your discretion!
+ */
func (ma *MathematicalSeries[T]) StandardDeviationLessThan(limit T) (bool, T) {
// If we have not yet accumulated a complete set of intervals,
@@ -112,6 +115,25 @@ func (ma *MathematicalSeries[T]) StandardDeviationLessThan(limit T) (bool, T) {
// Finally, the standard deviation is the square root
// of the variance.
sd := T(math.Sqrt(variance))
+ //sd := T(variance)
return T(sd) < limit, sd
}
+
+func (ma *MathematicalSeries[T]) IsNormallyDistributed() bool {
+ _, stddev := ma.StandardDeviationLessThan(0.0)
+ avg := float64(ma.CalculateAverage())
+
+ fstddev := float64(stddev)
+ within := float64(0)
+ for _, v := range ma.Values() {
+ if (avg-fstddev) <= float64(v) && float64(v) <= (avg+fstddev) {
+ within++
+ }
+ }
+ return within/float64(ma.divisor.Value()) >= 0.68
+}
+
+func (ma *MathematicalSeries[T]) Values() []T {
+ return ma.elements
+}
diff --git a/ms/ms_test.go b/ms/ms_test.go
index 0ba6da6..3eb3b4f 100644
--- a/ms/ms_test.go
+++ b/ms/ms_test.go
@@ -1,6 +1,7 @@
package ms
import (
+ "reflect"
"testing"
"github.com/network-quality/goresponsiveness/utilities"
@@ -81,3 +82,20 @@ func Test_StandardDeviationLessThan_Float(test *testing.T) {
test.Logf("Standard deviation calculation result: %v", sd)
}
}
+
+func Test_RotatingValues(test *testing.T) {
+ series := NewMathematicalSeries[int](5)
+
+ series.AddElement(1)
+ series.AddElement(2)
+ series.AddElement(3)
+ series.AddElement(4)
+ series.AddElement(5)
+
+ series.AddElement(6)
+ series.AddElement(7)
+
+ if !reflect.DeepEqual([]int{6, 7, 3, 4, 5}, series.Values()) {
+ test.Fatalf("Adding values does not properly erase earlier values.")
+ }
+}