hsa-app/internal/classify/pricing_test.go

32 lines
879 B
Go
Raw Normal View History

package classify
import (
"math"
"testing"
)
func TestCostCents_Haiku(t *testing.T) {
// 1500 input + 100 output on Haiku ($1/1M in, $5/1M out).
// input: 1500 * 100c/1e6 = 0.15c ; output: 100 * 500c/1e6 = 0.05c → 0.20c
got, ok := CostCents("claude-haiku-4-5-20251001", Usage{InputTokens: 1500, OutputTokens: 100})
if !ok {
t.Fatal("expected known model")
}
if math.Abs(got-0.20) > 1e-9 {
t.Errorf("cost = %v, want 0.20", got)
}
}
func TestCostCents_CacheTokensBilledAtInputRate(t *testing.T) {
got, _ := CostCents("claude-haiku-4-5", Usage{CacheReadTokens: 1_000_000})
if math.Abs(got-100) > 1e-9 { // 1M input-rate tokens = 100 cents
t.Errorf("cost = %v, want 100", got)
}
}
func TestCostCents_UnknownModel(t *testing.T) {
if _, ok := CostCents("some-future-model", Usage{InputTokens: 1000}); ok {
t.Error("expected ok=false for unknown model")
}
}