Files
silk/server-go/internal/service/cross_validate_test.go
2026-08-14 01:16:50 +08:00

45 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package service
import "testing"
func TestCrossValidate(t *testing.T) {
cases := []struct {
name string
aiClass string
lampResult string
wantOK bool
}{
{"AI异常+LAMP阳性 一致", "sick", "positive", true},
{"AI健康+LAMP阴性 一致", "healthy", "negative", true},
{"AI异常+LAMP阴性 不一致", "sick", "negative", false},
{"AI健康+LAMP阳性 不一致", "healthy", "positive", false},
{"AI未知+LAMP阳性 不一致", "unknown", "positive", false},
{"LAMP无效 不一致", "sick", "invalid", false},
{"无AI记录 不一致", "", "positive", false},
}
for _, c := range cases {
ok, reason := CrossValidate(c.aiClass, c.lampResult, []string{"核型多角体病"})
if ok != c.wantOK {
t.Errorf("%s: ok=%v, want %v(原因 %s", c.name, ok, c.wantOK, reason)
}
if reason == "" {
t.Errorf("%s: 缺少原因说明", c.name)
}
}
}
func TestAIClassFromDetections(t *testing.T) {
if got := AIClassFromDetections(nil); got != "unknown" {
t.Errorf("空检测应为 unknown,实际 %s", got)
}
if got := AIClassFromDetections([]AIDetection{{ClassName: "healthy", Confidence: 0.9}}); got != "healthy" {
t.Errorf("全健康应为 healthy,实际 %s", got)
}
if got := AIClassFromDetections([]AIDetection{{ClassName: "healthy"}, {ClassName: "sick", Confidence: 0.6}}); got != "sick" {
t.Errorf("含 sick 应为 sick,实际 %s", got)
}
if got := AIClassFromDetections([]AIDetection{{ClassName: "unknown", Confidence: 0.6}}); got != "unknown" {
t.Errorf("unknown 应为 unknown,实际 %s", got)
}
}