dropped-frame tracke
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"mxl-player/internal/playback"
|
||||
)
|
||||
|
||||
func TestVideoDropTracker(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
observations [][2]uint64
|
||||
want []uint64
|
||||
}{
|
||||
{
|
||||
name: "counts gaps within generation",
|
||||
observations: [][2]uint64{{1, 10}, {1, 11}, {1, 15}},
|
||||
want: []uint64{0, 0, 3},
|
||||
},
|
||||
{
|
||||
name: "higher index from new generation resets baseline",
|
||||
observations: [][2]uint64{{1, 10}, {2, 1000000}, {2, 1000001}},
|
||||
want: []uint64{0, 0, 0},
|
||||
},
|
||||
{
|
||||
name: "lower index from new generation resets baseline",
|
||||
observations: [][2]uint64{{1, 100}, {2, 5}, {2, 7}},
|
||||
want: []uint64{0, 0, 1},
|
||||
},
|
||||
{
|
||||
name: "index restart within generation resets baseline",
|
||||
observations: [][2]uint64{{1, 100}, {1, 0}, {1, 1}},
|
||||
want: []uint64{0, 0, 0},
|
||||
},
|
||||
{
|
||||
name: "zero is a valid first index",
|
||||
observations: [][2]uint64{{1, 0}, {1, 2}},
|
||||
want: []uint64{0, 1},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var tracker videoDropTracker
|
||||
source := playback.FeedConfig{Domain: "/mxl", UUID: "video"}
|
||||
for index, observation := range test.observations {
|
||||
got := tracker.Observe(observation[0], source, observation[1])
|
||||
if got != test.want[index] {
|
||||
t.Fatalf("Observe(%d, %d) = %d, want %d",
|
||||
observation[0], observation[1], got, test.want[index])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestVideoDropTrackerResetsWhenSourceChanges(t *testing.T) {
|
||||
var tracker videoDropTracker
|
||||
first := playback.FeedConfig{Domain: "/mxl", UUID: "first"}
|
||||
second := playback.FeedConfig{Domain: "/mxl", UUID: "second"}
|
||||
|
||||
if got := tracker.Observe(1, first, 10); got != 0 {
|
||||
t.Fatalf("first Observe() = %d, want 0", got)
|
||||
}
|
||||
if got := tracker.Observe(1, second, 1000000); got != 0 {
|
||||
t.Fatalf("source-changing Observe() = %d, want 0", got)
|
||||
}
|
||||
if got := tracker.Observe(1, second, 1000002); got != 1 {
|
||||
t.Fatalf("same-source Observe() = %d, want 1", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user