Files
silk/server-go/internal/service/trace_test.go
T

67 lines
2.1 KiB
Go
Raw 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 TestEnvironmentBacktrack(t *testing.T) {
// 高湿 + 温度突变 → 双触发
samples := []EnvSample{
{Temp: ptrF(28), Humidity: ptrF(85)},
{Temp: ptrF(32), Humidity: ptrF(90)},
}
r := EnvironmentBacktrack(samples, 80)
if !r.HighHumidity || !r.TempSwing {
t.Errorf("应同时检出高湿与温度突变: %+v", r)
}
// 正常环境
normal := []EnvSample{{Temp: ptrF(25), Humidity: ptrF(60)}}
r2 := EnvironmentBacktrack(normal, 80)
if r2.HighHumidity || r2.TempSwing || len(r2.Summary) == 0 {
t.Errorf("正常环境不应触发: %+v", r2)
}
}
func TestHistoryAssociation(t *testing.T) {
past := []PastEvent{{Disease: "白僵病", DaysAgo: 30}}
if !HistoryAssociation(past, "白僵病") {
t.Error("同病种历史发病应判连发性")
}
if HistoryAssociation(past, "软化病") {
t.Error("不同病种不应判连发性")
}
}
func TestTransmissionInference(t *testing.T) {
if mode, _ := TransmissionInference("白僵病"); mode != "接触传染/气流扩散" {
t.Errorf("白僵病传播方式 = %s", mode)
}
if mode, _ := TransmissionInference("微粒子病"); mode != "食下传染+胚种传染" {
t.Errorf("微粒子病传播方式 = %s", mode)
}
}
func TestDiseaseChecklist(t *testing.T) {
if len(DiseaseChecklist("核型多角体病")) < 3 {
t.Error("核型多角体病排查清单应 ≥3 项")
}
if len(DiseaseChecklist("未知病种")) != 0 {
t.Error("未知病种应返回空清单")
}
}
func TestAnalyzeChecklist(t *testing.T) {
items := []ChecklistAnswer{
{Key: "disinfect", Label: "上批次消毒是否彻底", Answer: "yes", InternalBias: true},
{Key: "tray_share", Label: "蚕具是否跨批次共用", Answer: "yes", InternalBias: true},
{Key: "mulberry", Label: "桑叶来源是否变更", Answer: "no", InternalBias: false},
}
origin, conf, conclusion := AnalyzeChecklist(items)
if origin != "internal" {
t.Errorf("内源倾向答案应判 internal,实际 %s(结论 %s", origin, conclusion)
}
if conf <= 0.5 {
t.Errorf("置信度应 >0.5,实际 %.2f", conf)
}
}
func ptrF(v float64) *float64 { return &v }