(t *testing.T)
| 267 | } |
| 268 | |
| 269 | func TestDetectInconsistencies(t *testing.T) { |
| 270 | config := DefaultQualityMetricsConfig() |
| 271 | qm := NewQualityMetrics(config) |
| 272 | qa := NewQualityAnalyzer(qm, nil) |
| 273 | |
| 274 | // 创建包含各种问题的记忆集合 |
| 275 | oldProvenance := NewProvenance(SourceUserInput, "user-1") |
| 276 | oldProvenance.CreatedAt = time.Now().Add(-200 * 24 * time.Hour) |
| 277 | oldProvenance.Confidence = 0.3 |
| 278 | |
| 279 | memories := []MemoryWithScore{ |
| 280 | { |
| 281 | DocID: "contradiction1", |
| 282 | Text: "The system is running", |
| 283 | Provenance: NewProvenance(SourceUserInput, "user-1"), |
| 284 | }, |
| 285 | { |
| 286 | DocID: "contradiction2", |
| 287 | Text: "The system is not running", |
| 288 | Provenance: NewProvenance(SourceUserInput, "user-2"), |
| 289 | }, |
| 290 | { |
| 291 | DocID: "duplicate1", |
| 292 | Text: "User logged in successfully", |
| 293 | Provenance: NewProvenance(SourceUserInput, "user-3"), |
| 294 | }, |
| 295 | { |
| 296 | DocID: "duplicate2", |
| 297 | Text: "User logged in successfully", |
| 298 | Provenance: NewProvenance(SourceUserInput, "user-4"), |
| 299 | }, |
| 300 | { |
| 301 | DocID: "old-and-low-conf", |
| 302 | Text: "Old and unreliable information", |
| 303 | Provenance: oldProvenance, |
| 304 | }, |
| 305 | } |
| 306 | |
| 307 | inconsistencies, err := qa.DetectInconsistencies(context.Background(), memories) |
| 308 | if err != nil { |
| 309 | t.Fatalf("DetectInconsistencies failed: %v", err) |
| 310 | } |
| 311 | |
| 312 | // 应该检测到多种类型的不一致性 |
| 313 | if len(inconsistencies) == 0 { |
| 314 | t.Error("should detect inconsistencies") |
| 315 | } |
| 316 | |
| 317 | // 统计各类型 |
| 318 | types := make(map[InconsistencyType]int) |
| 319 | for _, inc := range inconsistencies { |
| 320 | types[inc.Type]++ |
| 321 | } |
| 322 | |
| 323 | if types[InconsistencyContradiction] == 0 { |
| 324 | t.Error("should detect contradictions") |
| 325 | } |
| 326 |
nothing calls this directly
no test coverage detected