MCPcopy Create free account
hub / github.com/appleboy/CodeGPT / TestUsageString

Function TestUsageString

core/openai_test.go:9–65  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestUsageString(t *testing.T) {
10 tests := []struct {
11 name string
12 usage Usage
13 expected string
14 }{
15 {
16 name: "without details",
17 usage: Usage{
18 PromptTokens: 10,
19 CompletionTokens: 20,
20 TotalTokens: 30,
21 },
22 expected: "Prompt tokens: 10, Completion tokens: 20, Total tokens: 30",
23 },
24 {
25 name: "with cached tokens",
26 usage: Usage{
27 PromptTokens: 10,
28 CompletionTokens: 20,
29 TotalTokens: 30,
30 PromptTokensDetails: &openai.PromptTokensDetails{CachedTokens: 5},
31 },
32 expected: "Prompt tokens: 10 (CachedTokens: 5), Completion tokens: 20, Total tokens: 30",
33 },
34 {
35 name: "with reasoning tokens",
36 usage: Usage{
37 PromptTokens: 10,
38 CompletionTokens: 20,
39 TotalTokens: 30,
40 CompletionTokensDetails: &openai.CompletionTokensDetails{ReasoningTokens: 7},
41 },
42 expected: "Prompt tokens: 10, Completion tokens: 20 (ReasoningTokens: 7), Total tokens: 30",
43 },
44 {
45 name: "with both details",
46 usage: Usage{
47 PromptTokens: 15,
48 CompletionTokens: 25,
49 TotalTokens: 40,
50 PromptTokensDetails: &openai.PromptTokensDetails{CachedTokens: 3},
51 CompletionTokensDetails: &openai.CompletionTokensDetails{ReasoningTokens: 9},
52 },
53 expected: "Prompt tokens: 15 (CachedTokens: 3), Completion tokens: 25 (ReasoningTokens: 9), Total tokens: 40",
54 },
55 }
56
57 for _, tc := range tests {
58 t.Run(tc.name, func(t *testing.T) {
59 result := tc.usage.String()
60 if result != tc.expected {
61 t.Errorf("Usage.String() = %q, expected %q", result, tc.expected)
62 }
63 })
64 }
65}

Callers

nothing calls this directly

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected