2020-04-30 20:15:52 +02:00
|
|
|
package estimator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-06-09 14:13:30 +02:00
|
|
|
|
|
|
|
"sfu/rtptime"
|
2020-04-30 20:15:52 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEstimator(t *testing.T) {
|
2020-06-09 14:13:30 +02:00
|
|
|
now := rtptime.Jiffies()
|
|
|
|
e := New(rtptime.JiffiesPerSec)
|
2020-04-30 20:15:52 +02:00
|
|
|
|
|
|
|
e.estimate(now)
|
2020-05-31 23:47:12 +02:00
|
|
|
e.Accumulate(42)
|
|
|
|
e.Accumulate(128)
|
2020-06-09 14:13:30 +02:00
|
|
|
e.estimate(now + rtptime.JiffiesPerSec)
|
|
|
|
rate, packetRate :=
|
|
|
|
e.estimate(now + (rtptime.JiffiesPerSec * 1001) / 1000)
|
2020-04-30 20:15:52 +02:00
|
|
|
|
|
|
|
if rate != 42+128 {
|
|
|
|
t.Errorf("Expected %v, got %v", 42+128, rate)
|
|
|
|
}
|
2020-06-03 22:37:43 +02:00
|
|
|
if packetRate != 2 {
|
|
|
|
t.Errorf("Expected 2, got %v", packetRate)
|
|
|
|
}
|
2020-05-31 23:54:55 +02:00
|
|
|
|
|
|
|
totalP, totalB := e.Totals()
|
|
|
|
if totalP != 2 {
|
|
|
|
t.Errorf("Expected 2, got %v", totalP)
|
|
|
|
}
|
|
|
|
if totalB != 42+128 {
|
|
|
|
t.Errorf("Expected %v, got %v", 42+128, totalB)
|
|
|
|
}
|
2020-06-03 22:37:43 +02:00
|
|
|
|
|
|
|
e.Accumulate(12)
|
|
|
|
|
|
|
|
totalP, totalB = e.Totals()
|
|
|
|
if totalP != 3 {
|
|
|
|
t.Errorf("Expected 2, got %v", totalP)
|
|
|
|
}
|
|
|
|
if totalB != 42+128+12 {
|
|
|
|
t.Errorf("Expected %v, got %v", 42+128, totalB)
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:15:52 +02:00
|
|
|
}
|