usage_test.go 1.2 KB

123456789101112131415161718192021222324252627282930
  1. package xai
  2. import "testing"
  3. func TestIncludeIndependentReasoningTokens(t *testing.T) {
  4. t.Parallel()
  5. tests := []struct {
  6. name string
  7. input, output, total, reason int64
  8. want int64
  9. }{
  10. {name: "xAI chat example", input: 32, output: 9, total: 135, reason: 94, want: 103},
  11. {name: "xAI responses example", input: 32, output: 9, total: 151, reason: 110, want: 119},
  12. {name: "OpenAI inclusive output", input: 32, output: 103, total: 135, reason: 94, want: 103},
  13. {name: "gap smaller than reasoning", input: 10, output: 20, total: 33, reason: 5, want: 23},
  14. {name: "absent total", input: 10, output: 20, total: 0, reason: 5, want: 20},
  15. {name: "total already complete", input: 10, output: 20, total: 30, reason: 5, want: 20},
  16. {name: "inconsistent undershoot", input: 10, output: 20, total: 25, reason: 5, want: 20},
  17. {name: "zero reasoning", input: 10, output: 20, total: 35, reason: 0, want: 20},
  18. }
  19. for _, tt := range tests {
  20. t.Run(tt.name, func(t *testing.T) {
  21. t.Parallel()
  22. got := IncludeIndependentReasoningTokens(tt.input, tt.output, tt.total, tt.reason)
  23. if got != tt.want {
  24. t.Fatalf("got %d, want %d", got, tt.want)
  25. }
  26. })
  27. }
  28. }