feat(server-go): 分子检测扩展(qPCR Ct 判读/SERS 光谱上传/光谱库,#19)
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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 应被拒绝")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user