bandwidth/bandwidth_test.go

45 lines
888 B
Go

package bandwidth
import (
"log"
"testing"
"time"
)
func init() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
}
func validate(t *testing.T, actual, expected []float64) {
if len(actual) != len(expected) {
t.Errorf("len is not same: %d expected %d", len(actual), len(expected))
}
for i, _ := range actual {
if actual[i] != expected[i] {
t.Errorf("%dth: got %f expected %f", i, actual[i], expected[i])
}
}
}
func TestEmpty(t *testing.T) {
bw, err := NewBandwidth([]int{1, 10, 60}, 100*time.Millisecond)
if err != nil {
t.Error(err)
}
go bw.Run()
bw.rxstream = []int{1, 10, 60}
validate(t, <-bw.Rx, []float64{})
}
func TestEmptySeconds(t *testing.T) {
_, err := NewBandwidth([]int{}, 100*time.Millisecond)
if err == nil {
t.Error(err)
}
}
func TestA(t *testing.T) {
bw, _ := NewBandwidth([]int{1, 10, 30}, 1*time.Second)
log.Printf("%+v", bw)
}