github.com/simpleiot/simpleiot@v0.18.3/data/time_window_avg_test.go (about) 1 package data 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 ) 8 9 func TestNewPoint(t *testing.T) { 10 if testing.Short() { 11 t.Skip("skipping test in short mode") 12 } 13 14 var avgPoint Point 15 16 point := Point{ 17 Time: time.Now(), 18 Value: 200, 19 } 20 21 pointAverager := NewTimeWindowAverager(3*time.Second, func(avg Point) { 22 fmt.Println("Average (Value): ", avg.Value) 23 fmt.Println() 24 avgPoint = avg 25 }, "hello") 26 27 pointTicker := time.NewTicker(300 * time.Millisecond) 28 startTime := time.Now() 29 30 for time.Since(startTime) < time.Second*6 { 31 <-pointTicker.C 32 pointAverager.NewPoint(point) 33 34 if avgPoint.Value != point.Value { 35 t.Error("point avg is not correct") 36 } 37 } 38 }