MCPcopy Create free account
hub / github.com/diillson/chatcli / TestFormatTokenCount

Function TestFormatTokenCount

cli/context_handler_test.go:7–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5)
6
7func TestFormatTokenCount(t *testing.T) {
8 tests := []struct {
9 name string
10 tokens int64
11 want string
12 }{
13 {
14 name: "zero",
15 tokens: 0,
16 want: "0",
17 },
18 {
19 name: "small number",
20 tokens: 500,
21 want: "500",
22 },
23 {
24 name: "just below 1K",
25 tokens: 999,
26 want: "999",
27 },
28 {
29 name: "exactly 1K",
30 tokens: 1_000,
31 want: "1.0K",
32 },
33 {
34 name: "mid thousands",
35 tokens: 25_500,
36 want: "25.5K",
37 },
38 {
39 name: "large thousands",
40 tokens: 999_999,
41 want: "1000.0K",
42 },
43 {
44 name: "exactly 1M",
45 tokens: 1_000_000,
46 want: "1.0M",
47 },
48 {
49 name: "multi million",
50 tokens: 2_500_000,
51 want: "2.5M",
52 },
53 }
54
55 for _, tc := range tests {
56 t.Run(tc.name, func(t *testing.T) {
57 got := formatTokenCount(tc.tokens)
58 if got != tc.want {
59 t.Errorf("formatTokenCount(%d) = %q, want %q", tc.tokens, got, tc.want)
60 }
61 })
62 }
63}

Callers

nothing calls this directly

Calls 3

formatTokenCountFunction · 0.85
ErrorfMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected