ostat/ostat_test.go

46 lines
928 B
Go
Raw Normal View History

2013-12-28 23:56:48 -08:00
package ostat
import (
"math"
"testing"
)
func TestInsert(t *testing.T) {
os := NewOnlineStat()
v := []float64{4, 7, 13, 16}
for _, i := range v {
os.Push(i)
}
if os.Min != 4 {
t.Errorf("incorrectly calculated min")
}
if os.Max != 16 {
t.Errorf("incorrectly calculated max")
}
if m, _ := os.Mean(); m != 10.0 {
t.Errorf("incorrect mean")
}
if variance, _ := os.Variance(); variance != 30.0 {
t.Errorf("incorrect variance: %f", variance)
}
if stdev, _ := os.StdDev(); stdev != math.Sqrt(30.0) {
t.Errorf("incorrect stdev: %f", stdev)
}
}
func TestEmpty(t *testing.T) {
os := NewOnlineStat()
_, err := os.Mean()
if err == nil {
t.Errorf("failure to notify the running stat was empty")
}
_, err = os.Variance()
if err == nil {
t.Errorf("failure to notify the running stat was empty")
}
_, err = os.StdDev()
if err == nil {
t.Errorf("failure to notify the running stat was empty")
}
}