old_console/correlator/stat/stat_test.go
2024-11-02 14:12:45 +03:00

61 lines
992 B
Go

package stat
import (
"testing"
"time"
)
func TestTimeAdd(t *testing.T) {
var avg AvgTime
for i := 0; i < avgCount+1; i++ {
avg.Add(time.Second)
}
if avg.Value != time.Second {
t.Errorf("Got bad average time: %v", avg.Value)
}
}
func TestTimeAdd2(t *testing.T) {
var avg AvgTime
for i := 0; i < avgCount*10+1; i++ {
avg.Add(time.Second)
}
if avg.Value != time.Second {
t.Errorf("Got bad average time: %v", avg.Value)
}
}
func TestCopy(t *testing.T) {
avg1 := AvgTime{Value: time.Second, index: 2}
var avg2 AvgTime
avg2 = avg1
if avg2.Value != time.Second {
t.Errorf("Bad value: %v", avg2.Value)
}
if avg2.index != 2 {
t.Errorf("Bad index: %v", avg2.index)
}
}
func TestAvgTime_AddStat(t *testing.T) {
var avg1, avg2 AvgTime
avg1.Add(time.Second)
avg2.Add(time.Second * 2)
avg1.AddStat(&avg2)
goodTime := time.Millisecond * 300
if avg1.Value != goodTime {
t.Errorf("Bad average time value, expect %v, got %v", goodTime, avg1.Value)
}
}