Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCounterSeriesIsMonotonicAndDeterministic(t *testing.T) {
|
|
start := time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC)
|
|
a := counterSeries(patternDiurnal, start, 3*24*60, time.Minute, 1_000_000, 7)
|
|
b := counterSeries(patternDiurnal, start, 3*24*60, time.Minute, 1_000_000, 7)
|
|
for i := range a {
|
|
if a[i] != b[i] {
|
|
t.Fatalf("not deterministic at %d", i)
|
|
}
|
|
if i > 0 && a[i] < a[i-1] {
|
|
t.Fatalf("decreased at %d", i)
|
|
}
|
|
}
|
|
if a[0] != 0 {
|
|
t.Fatalf("starts at %v, want 0", a[0])
|
|
}
|
|
meanRate := a[len(a)-1] / (float64(len(a)-1) * 60)
|
|
if meanRate < 0.8e6 || meanRate > 1.4e6 {
|
|
t.Fatalf("mean rate %.0f B/s drifted from 1e6", meanRate)
|
|
}
|
|
}
|
|
|
|
func TestDiurnalEveningBusierThanNight(t *testing.T) {
|
|
// Monday, so the weekend factor does not interfere. Averaged over many days the noise washes out.
|
|
var night, evening float64
|
|
for d := 0; d < 28; d++ {
|
|
day := time.Date(2026, 9, 7, 0, 0, 0, 0, time.UTC).AddDate(0, 0, d)
|
|
if wd := day.Weekday(); wd == time.Saturday || wd == time.Sunday {
|
|
continue
|
|
}
|
|
night += rateFactor(patternDiurnal, day.Add(5*time.Hour), 1)
|
|
evening += rateFactor(patternDiurnal, day.Add(20*time.Hour), 1)
|
|
}
|
|
if evening < 2*night {
|
|
t.Fatalf("evening %.2f is not clearly busier than night %.2f", evening, night)
|
|
}
|
|
}
|
|
|
|
func TestFlatPatternIsConstant(t *testing.T) {
|
|
if f := rateFactor(patternFlat, time.Now(), 3); f != 1 {
|
|
t.Fatalf("flat factor %v", f)
|
|
}
|
|
}
|
|
|
|
func TestDefaultMeanIsStableAndBounded(t *testing.T) {
|
|
m := defaultMeanBytesPerSec("01abc", 1)
|
|
if m != defaultMeanBytesPerSec("01abc", 1) || m < 2*125_000 || m > 60*125_000 {
|
|
t.Fatalf("mean %v", m)
|
|
}
|
|
}
|