Files
aego/platform/web/message_target_test.go
sanspie 5eb1832907
ci-platforms / darwin amd64 smoke (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Failing after 15m28s
ci / release (push) Skipped
ci-platforms / windows amd64 smoke (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
ci / checks (push) Successful in 7m47s
Complete Stage 12 for v0.12.0
2026-11-05 11:46:53 +03:00

36 lines
1.0 KiB
Go

package web
import (
"math"
"testing"
)
func TestMessageTargetBlocks(t *testing.T) {
for _, tc := range []struct {
name string
latency float64
rate, frames int
want int
}{
{"zero latency", 0, 48000, 512, 6},
{"negative latency", -1, 48000, 512, 6},
{"NaN latency", math.NaN(), 48000, 512, 6},
{"infinite latency", math.Inf(1), 48000, 512, 6},
{"missing rate", 0.04, 0, 512, 6},
{"missing frames", 0.04, 48000, 0, 6},
{"2048 frame burst", 2048.0 / 48000, 48000, 512, 6},
{"partial block", 2049.0 / 48000, 48000, 512, 6},
{"five whole blocks", 2560.0 / 48000, 48000, 512, 6},
{"more than five blocks", 2561.0 / 48000, 48000, 512, 7},
{"bounded target", 1, 48000, 512, 12},
{"overflow saturates", math.MaxFloat64, 48000, 512, 12},
{"message transport is not ring bounded", 0.2, 48000, 2048, 6},
} {
t.Run(tc.name, func(t *testing.T) {
if got := messageTargetBlocks(tc.latency, tc.rate, tc.frames); got != tc.want {
t.Fatalf("target = %d, want %d", got, tc.want)
}
})
}
}