started the stats module

This commit is contained in:
didier.amyot committed 2014-05-13 20:59:51 -04:00
1 parent 4ff72d3080
commit f6809a20e6
2 files changed
+76

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
package main
import (
"testing"
)
func TestNewStats(t *testing.T) {
s := NewStatAggregator()
if s.n != 0 ||
s.sum != 0 ||
s.sumOfTheSquares != 0 ||
len(s.histogram) != initialLength ||
s.min != veryBig ||
s.max != verySmall {
t.Fail()
}
}
func TestAddStatsBasic(t *testing.T) {
numbers := []float64{-1, 1, 20, 3}
c := make(chan float64)
o := make(chan *Stats)
s := NewStatAggregator()
go s.AddStats(c, o)
for _, n := range numbers {
c <- n
}
close(c)
<-o
if s.n != 4. || s.min != -1. || s.max != 20. || s.sum != 23. || s.sumOfTheSquares != 411. {
t.Error(">>>", s.max, s.min)
}
}