package service import "testing" func TestRecommendMethodNoDevices(t *testing.T) { got := RecommendMethod(DetectionRecommendInput{}) if len(got) != 0 { t.Errorf("无可用设备应返回空,实际 %+v", got) } } func TestRecommendMethodLowCost(t *testing.T) { got := RecommendMethod(DetectionRecommendInput{ HasLamp: true, HasSers: true, HasQPCR: true, CostPreference: "low_cost", }) if len(got) == 0 || got[0].Method != "lamp" { t.Errorf("低成本偏好应首选 LAMP,实际 %+v", got) } } func TestRecommendMethodFastest(t *testing.T) { got := RecommendMethod(DetectionRecommendInput{ HasLamp: true, HasSers: true, HasQPCR: true, CostPreference: "fastest", }) if len(got) == 0 || got[0].Method != "sers" { t.Errorf("最快偏好应首选 SERS,实际 %+v", got) } } func TestRecommendMethodUrgentNoSERS(t *testing.T) { got := RecommendMethod(DetectionRecommendInput{ HasLamp: true, HasQPCR: true, Urgency: "urgent", }) if len(got) == 0 || got[0].Method != "lamp" { t.Errorf("紧急且无 SERS 应首选 LAMP,实际 %+v", got) } } func TestRecommendMethodNoviceAvoidsQPCR(t *testing.T) { got := RecommendMethod(DetectionRecommendInput{ HasLamp: true, HasSers: true, HasQPCR: true, OperatorLevel: "novice", }) if len(got) == 0 { t.Fatal("应有推荐") } if got[len(got)-1].Method == "qpcr" { // qPCR 难度高,新手应排在最后(除非仅此可选) } // 至少 qPCR 不应排第一 if got[0].Method == "qpcr" { t.Errorf("新手不应首选 qPCR,实际 %+v", got) } } func TestRecommendMethodOnlyHyperspectral(t *testing.T) { got := RecommendMethod(DetectionRecommendInput{HasHyperspectral: true}) if len(got) != 1 || got[0].Method != "hyperspectral" { t.Errorf("仅有高光谱时应推荐且标注待验证,实际 %+v", got) } }