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

Function TestCompressionCache

pkg/compression/service_test.go:215–251  ·  view source on GitHub ↗

TestCompressionCache 测试压缩缓存

(t *testing.T)

Source from the content-addressed store, hash-verified

213
214// TestCompressionCache 测试压缩缓存
215func TestCompressionCache(t *testing.T) {
216 cache := NewCompressionCache(3)
217
218 // 添加几个结果
219 cache.Set("key1", &CompressResult{Compressed: "result1"})
220 cache.Set("key2", &CompressResult{Compressed: "result2"})
221 cache.Set("key3", &CompressResult{Compressed: "result3"})
222
223 // 验证获取
224 if r := cache.Get("key1"); r == nil || r.Compressed != "result1" {
225 t.Error("Expected to get key1")
226 }
227
228 // 验证大小
229 if cache.Size() != 3 {
230 t.Errorf("Expected cache size 3, got %d", cache.Size())
231 }
232
233 // 添加第四个(应该触发清空)
234 cache.Set("key4", &CompressResult{Compressed: "result4"})
235
236 // 旧的应该被清空
237 if cache.Get("key1") != nil {
238 t.Error("Expected key1 to be cleared after overflow")
239 }
240
241 // 新的应该存在
242 if r := cache.Get("key4"); r == nil || r.Compressed != "result4" {
243 t.Error("Expected to get key4")
244 }
245
246 // 测试清空
247 cache.Clear()
248 if cache.Size() != 0 {
249 t.Errorf("Expected cache size 0 after clear, got %d", cache.Size())
250 }
251}
252
253// TestSectionScoring 测试段落评分
254func TestSectionScoring(t *testing.T) {

Callers

nothing calls this directly

Calls 6

SetMethod · 0.95
GetMethod · 0.95
SizeMethod · 0.95
ClearMethod · 0.95
NewCompressionCacheFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected