TestCompressionCache 测试压缩缓存
(t *testing.T)
| 213 | |
| 214 | // TestCompressionCache 测试压缩缓存 |
| 215 | func 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 测试段落评分 |
| 254 | func TestSectionScoring(t *testing.T) { |