Files
silk/server-go/internal/model/molecular_test.go
T

46 lines
1.3 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 model
import "testing"
func TestJudgeQPCR(t *testing.T) {
cases := []struct {
name string
cts []float64
threshold float64
want string
}{
{"Ct32 阳性", []float64{32}, 35, "positive"},
{"Ct38 阴性", []float64{38}, 35, "negative"},
{"无Ct 阴性", nil, 35, "negative"},
{"多个Ct含阳性", []float64{33, 37}, 35, "positive"},
{"自定义阈值40", []float64{38}, 40, "positive"},
{"阈值为0用默认35", []float64{38}, 0, "negative"},
}
for _, c := range cases {
got, reason := JudgeQPCR(c.cts, c.threshold)
if got != c.want {
t.Errorf("%s: result=%s, want %s(原因 %s", c.name, got, c.want, reason)
}
if reason == "" {
t.Errorf("%s: 缺少判读说明", c.name)
}
}
}
func TestValidateSpectrumFile(t *testing.T) {
for _, name := range []string{"a.csv", "b.txt", "c.json"} {
if err := ValidateSpectrumFile(name, 1024); err != nil {
t.Errorf("%s 应被允许: %v", name, err)
}
}
if err := ValidateSpectrumFile("a.jpg", 1024); err == nil {
t.Error("图片扩展名不应被允许")
}
if err := ValidateSpectrumFile("a.csv", 0); err == nil {
t.Error("空文件应被拒绝")
}
if err := ValidateSpectrumFile("a.csv", maxSpectrumSize+1); err == nil {
t.Error("超 5MB 应被拒绝")
}
}