package main import ( "testing" "github.com/kami/maven/internal/memory" ) func TestBestRecall(t *testing.T) { const min = 0.55 t.Run("empty results", func(t *testing.T) { if _, ok := bestRecall(nil, min); ok { t.Error("empty results returned ok") } }) t.Run("top below threshold", func(t *testing.T) { res := []memory.Result{{Score: 0.4, Meta: map[string]string{"text": "выпил воды"}}} if _, ok := bestRecall(res, min); ok { t.Error("below-threshold hit returned ok") } }) t.Run("hit without text meta", func(t *testing.T) { res := []memory.Result{{Score: 0.9, Meta: map[string]string{"type": "fact"}}} if _, ok := bestRecall(res, min); ok { t.Error("textless hit returned ok") } }) t.Run("clearing hit returns its text", func(t *testing.T) { res := []memory.Result{ {Score: 0.82, Meta: map[string]string{"text": "выпил воды в три часа", "type": "fact"}}, {Score: 0.60, Meta: map[string]string{"text": "другое"}}, } got, ok := bestRecall(res, min) if !ok { t.Fatal("clearing hit not returned") } if got != "выпил воды в три часа" { t.Errorf("wrong text: %q", got) } }) }