33 lines
988 B
Go
33 lines
988 B
Go
package service
|
|
|
|
import "testing"
|
|
|
|
func TestAggregateRegionStats(t *testing.T) {
|
|
entries := []RegionDiseaseEntry{
|
|
{Region: "A镇", Disease: "白僵病"},
|
|
{Region: "A镇", Disease: "白僵病"},
|
|
{Region: "A镇", Disease: "软化病"},
|
|
{Region: "B乡", Disease: "白僵病"},
|
|
{Region: "", Disease: "白僵病"},
|
|
}
|
|
stats := AggregateRegionStats(entries)
|
|
if len(stats) != 2 {
|
|
t.Fatalf("统计区域数 = %d, want 2(空区域应剔除)", len(stats))
|
|
}
|
|
if stats[0].Region != "A镇" || stats[0].Total != 3 {
|
|
t.Errorf("A镇应排第一且 total=3,实际 %+v", stats[0])
|
|
}
|
|
if stats[0].Diseases["白僵病"] != 2 || stats[0].Diseases["软化病"] != 1 {
|
|
t.Errorf("A镇病种分布不正确: %+v", stats[0].Diseases)
|
|
}
|
|
if stats[1].Region != "B乡" || stats[1].Total != 1 {
|
|
t.Errorf("B乡统计不正确: %+v", stats[1])
|
|
}
|
|
}
|
|
|
|
func TestAggregateRegionStatsEmpty(t *testing.T) {
|
|
if len(AggregateRegionStats(nil)) != 0 {
|
|
t.Error("空输入应返回空结果")
|
|
}
|
|
}
|