2020-06-27 12:39:42 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStats(t *testing.T) {
|
|
|
|
N := 16
|
|
|
|
ss := make([]*stats, N)
|
2020-06-29 22:31:05 +00:00
|
|
|
rng := rand.New(rand.NewSource(1))
|
2020-06-27 12:39:42 +00:00
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
ss[i] = &stats{}
|
2020-06-29 22:31:05 +00:00
|
|
|
maxJ := rng.Intn(1000)
|
2020-06-27 12:39:42 +00:00
|
|
|
for j := 0; j < maxJ; j++ {
|
2020-06-29 22:31:05 +00:00
|
|
|
ss[i].AddPoint(rng.NormFloat64()*5 + 500)
|
2020-06-27 12:39:42 +00:00
|
|
|
}
|
|
|
|
t.Logf("mean: %f, stddev: %f, count %f", ss[i].mean, math.Sqrt(ss[i].variance()), ss[i].count)
|
|
|
|
}
|
|
|
|
out := &stats{}
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
out.Combine(ss[i])
|
|
|
|
t.Logf("combine: mean: %f, stddev: %f", out.mean, math.Sqrt(out.variance()))
|
|
|
|
}
|
|
|
|
}
|