You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

  1. package service
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/require"
  5. )
  6. func TestEstimateTokenClassifiesWordNumberAndUnicodeBoundaries(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. text string
  10. want int
  11. }{
  12. {name: "empty", text: "", want: 0},
  13. {name: "latin word", text: "hello", want: 2},
  14. {name: "latin number transition", text: "v2", want: 3},
  15. {name: "cjk", text: "你", want: 1},
  16. {name: "emoji", text: "🙂", want: 3},
  17. {name: "url delimiter", text: "/", want: 1},
  18. }
  19. for _, tt := range tests {
  20. t.Run(tt.name, func(t *testing.T) {
  21. require.Equal(t, tt.want, EstimateToken(OpenAI, tt.text))
  22. })
  23. }
  24. }
  25. func TestEstimateTokenByModelSelectsProviderAndEmptyInputIsFree(t *testing.T) {
  26. require.Equal(t, 0, EstimateTokenByModel("gpt-5", ""))
  27. require.Equal(t, EstimateToken(Gemini, "hello"), EstimateTokenByModel("GEMINI-2.5-PRO", "hello"))
  28. require.Equal(t, EstimateToken(Claude, "hello"), EstimateTokenByModel("claude-sonnet", "hello"))
  29. require.Equal(t, EstimateToken(OpenAI, "hello"), EstimateTokenByModel("other-model", "hello"))
  30. }