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

Function TestPreferenceManager_GetTopPreferences

pkg/memory/preference_test.go:303–338  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

301}
302
303func TestPreferenceManager_GetTopPreferences(t *testing.T) {
304 manager := NewPreferenceManager(DefaultPreferenceManagerConfig())
305
306 // 添加多个偏好(不同强度)
307 prefs := []*Preference{
308 {UserID: "user-1", Category: CategoryUI, Key: "theme", Value: "dark", Strength: 0.9, Confidence: 0.9},
309 {UserID: "user-1", Category: CategoryUI, Key: "font", Value: "mono", Strength: 0.5, Confidence: 0.8},
310 {UserID: "user-1", Category: CategoryLanguage, Key: "lang", Value: "zh", Strength: 0.8, Confidence: 1.0},
311 }
312
313 for _, pref := range prefs {
314 if err := manager.AddPreference(context.Background(), pref); err != nil {
315 t.Fatalf("AddPreference failed: %v", err)
316 }
317 }
318
319 // 获取 TOP 2
320 top, err := manager.GetTopPreferences(context.Background(), "user-1", 2)
321 if err != nil {
322 t.Fatalf("GetTopPreferences failed: %v", err)
323 }
324
325 if len(top) != 2 {
326 t.Errorf("GetTopPreferences returned %d preferences, want 2", len(top))
327 }
328
329 // 验证排序
330 if top[0].Strength < top[1].Strength {
331 t.Error("preferences should be sorted by strength (descending)")
332 }
333
334 // 验证第一个是强度最高的
335 if top[0].Key != "theme" {
336 t.Errorf("top[0].Key = %s, want 'theme'", top[0].Key)
337 }
338}
339
340func TestPreferenceManager_ApplyDecay(t *testing.T) {
341 config := DefaultPreferenceManagerConfig()

Callers

nothing calls this directly

Calls 5

AddPreferenceMethod · 0.95
GetTopPreferencesMethod · 0.95
NewPreferenceManagerFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected