haixunMaster/haixun-backend/internal/library/knowledge/patrol_rank_test.go

46 lines
1.9 KiB
Go
Raw Permalink Normal View History

2026-06-24 16:48:56 +00:00
package knowledge
import "testing"
func TestSelectTopPatrolTagsLimitsAndDedupes(t *testing.T) {
tags := SelectTopPatrolTags([]PatrolTagCandidate{
{Tag: "化療 沐浴乳", Score: 100, Reason: "受眾提問", Intent: patrolIntentRelevance},
{Tag: "化療 沐浴乳 推薦", Score: 98, Reason: "受眾提問", Intent: patrolIntentRelevance},
{Tag: "無香沐浴乳 推薦", Score: 90, Reason: "產品匹配", Intent: patrolIntentRelevance},
{Tag: "乳癌 沐浴乳", Score: 88, Reason: "內容支柱", Intent: patrolIntentRelevance},
{Tag: "荷爾蒙 敏感", Score: 80, Reason: "內容支柱", Intent: patrolIntentRelevance},
{Tag: "化療 皮膚", Score: 75, Reason: "高相關延伸", Intent: patrolIntentRelevance},
{Tag: "病友 沐浴乳", Score: 70, Reason: "周邊情境", Intent: patrolIntentRelevance},
{Tag: "抗敏 沐浴乳", Score: 65, Reason: "置入產品", Intent: patrolIntentRelevance},
{Tag: "香精 過敏", Score: 60, Reason: "周邊情境", Intent: patrolIntentRelevance},
}, MaxTopPatrolTags)
if len(tags) != MaxTopPatrolTags {
t.Fatalf("expected %d tags, got %d: %v", MaxTopPatrolTags, len(tags), tags)
}
if tags[0] != "化療 沐浴乳" {
t.Fatalf("expected highest score first, got %q", tags[0])
}
}
func TestCollectPatrolTagsCapsOutput(t *testing.T) {
tags := CollectPatrolTags(PatrolTagInput{
ProductName: "抗敏無香沐浴露",
MatchTags: []string{"化療", "無香沐浴乳", "乳癌"},
Questions: []string{
"化療後皮膚敏感要換什麼沐浴乳",
"乳癌治療中不能用有香味的沐浴乳嗎",
"癌症病人適合用的無香沐浴乳推薦",
"荷爾蒙治療皮膚乾癢怎麼挑沐浴乳",
},
Pillars: []string{
"化療皮膚敏感無香沐浴乳",
"乳癌病友沐浴用品挑選",
"荷爾蒙治療對香味敏感",
"癌症康復後換清潔品牌",
},
})
if len(tags) > MaxTopPatrolTags {
t.Fatalf("expected <=%d tags, got %d: %v", MaxTopPatrolTags, len(tags), tags)
}
}