MCPcopy Create free account
hub / github.com/astercloud/aster / TestSimpleTokenCounter_Count

Function TestSimpleTokenCounter_Count

pkg/context/token_counter_test.go:8–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestSimpleTokenCounter_Count(t *testing.T) {
9 tests := []struct {
10 name string
11 config ModelConfig
12 text string
13 wantMin int
14 wantMax int
15 }{
16 {
17 name: "empty text",
18 config: GPT4Config,
19 text: "",
20 wantMin: 0,
21 wantMax: 0,
22 },
23 {
24 name: "simple english text",
25 config: GPT4Config,
26 text: "Hello, world!",
27 wantMin: 2,
28 wantMax: 5,
29 },
30 {
31 name: "chinese text",
32 config: ClaudeSonnet45Config,
33 text: "你好,世界!",
34 wantMin: 1,
35 wantMax: 3,
36 },
37 {
38 name: "mixed text",
39 config: GPT4Config,
40 text: "Hello 世界! This is a test.",
41 wantMin: 5,
42 wantMax: 10,
43 },
44 {
45 name: "long text",
46 config: GPT4Config,
47 text: "This is a longer piece of text that should result in more tokens being counted.",
48 wantMin: 15,
49 wantMax: 25,
50 },
51 }
52
53 for _, tt := range tests {
54 t.Run(tt.name, func(t *testing.T) {
55 counter := NewSimpleTokenCounter(tt.config)
56 got, err := counter.Count(context.Background(), tt.text)
57 if err != nil {
58 t.Errorf("Count() error = %v", err)
59 return
60 }
61 if got < tt.wantMin || got > tt.wantMax {
62 t.Errorf("Count() = %v, want between %v and %v", got, tt.wantMin, tt.wantMax)
63 }
64 })
65 }

Callers

nothing calls this directly

Calls 3

CountMethod · 0.95
NewSimpleTokenCounterFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected