nub/internal/tokens/calibrate_test.go
Tom a97013d876 initial commit
- v 0.1.0 siehe CHANGELOG.md
2026-07-25 11:08:01 +02:00

35 lines
1 KiB
Go

package tokens
import "testing"
func TestCalibrator_ConvergesTowardObservedRatio(t *testing.T) {
c := NewCalibrator()
for i := 0; i < 50; i++ {
c.Observe(100, 200) // Modell verbraucht durchweg doppelt so viele Tokens wie geschätzt
}
adjusted := c.Adjust(100)
// Nach Konvergenz: factor ~2.0, plus 15% Sicherheitsabstand -> ~230.
if adjusted < 220 || adjusted > 240 {
t.Errorf("adjusted = %d, want ~230 after convergence to ratio 2.0", adjusted)
}
}
func TestCalibrator_IgnoresZeroObservations(t *testing.T) {
c := NewCalibrator()
c.Observe(0, 100)
c.Observe(100, 0)
// Ohne gültige Beobachtung bleibt der Faktor bei 1.0 (+15% Sicherheitsabstand).
adjusted := c.Adjust(100)
if adjusted < 110 || adjusted > 120 {
t.Errorf("adjusted = %d, want ~115 (factor still 1.0)", adjusted)
}
}
func TestEstimate_NonEmpty(t *testing.T) {
if Estimate("") != 0 {
t.Error("empty string should estimate to 0 tokens")
}
if Estimate("hello world") <= 0 {
t.Error("non-empty text should estimate to > 0 tokens")
}
}