-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProjectTokenSummaryTests.swift
More file actions
103 lines (95 loc) · 3.06 KB
/
ProjectTokenSummaryTests.swift
File metadata and controls
103 lines (95 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import Testing
@testable import AIBatteryCore
@Suite("ProjectTokenSummary")
struct ProjectTokenSummaryTests {
@Test func totalTokens_sumsAllTypes() {
let summary = ProjectTokenSummary(
id: "test",
projectName: "test",
inputTokens: 100,
outputTokens: 200,
cacheReadTokens: 300,
cacheWriteTokens: 400,
estimatedCost: 0.50
)
#expect(summary.totalTokens == 1000)
}
@Test func totalTokens_zeroWhenAllZero() {
let summary = ProjectTokenSummary(
id: "/workspace/empty",
projectName: "empty",
inputTokens: 0,
outputTokens: 0,
cacheReadTokens: 0,
cacheWriteTokens: 0,
estimatedCost: 0
)
#expect(summary.totalTokens == 0)
}
@Test func id_isUsedAsIdentifiable() {
let summary = ProjectTokenSummary(
id: "/Users/kyle/projects/myapp",
projectName: "myapp",
inputTokens: 500,
outputTokens: 250,
cacheReadTokens: 0,
cacheWriteTokens: 0,
estimatedCost: 1.50
)
#expect(summary.id == "/Users/kyle/projects/myapp")
}
@Test func projectName_displaysLastPathComponent() {
// Simulates what UsageAggregator.buildProjectTokens does
let cwd = "/Users/kyle/projects/my-app"
let displayName = URL(fileURLWithPath: cwd).lastPathComponent
let summary = ProjectTokenSummary(
id: cwd,
projectName: displayName,
inputTokens: 100,
outputTokens: 50,
cacheReadTokens: 0,
cacheWriteTokens: 0,
estimatedCost: 0.30
)
#expect(summary.projectName == "my-app")
}
@Test func otherProject_usedForMissingCwd() {
let summary = ProjectTokenSummary(
id: "Other",
projectName: "Other",
inputTokens: 100,
outputTokens: 50,
cacheReadTokens: 0,
cacheWriteTokens: 0,
estimatedCost: 0.10
)
#expect(summary.id == "Other")
#expect(summary.projectName == "Other")
#expect(summary.totalTokens == 150)
}
@Test func estimatedCost_storedDirectly() {
let summary = ProjectTokenSummary(
id: "test",
projectName: "test",
inputTokens: 1_000_000,
outputTokens: 500_000,
cacheReadTokens: 2_000_000,
cacheWriteTokens: 100_000,
estimatedCost: 18.75
)
#expect(summary.estimatedCost == 18.75)
#expect(summary.totalTokens == 3_600_000)
}
@Test func largeTokenCounts_noOverflow() {
let summary = ProjectTokenSummary(
id: "large",
projectName: "large",
inputTokens: 500_000_000,
outputTokens: 200_000_000,
cacheReadTokens: 800_000_000,
cacheWriteTokens: 100_000_000,
estimatedCost: 5000.0
)
#expect(summary.totalTokens == 1_600_000_000)
}
}