Files
silk/server-go/internal/service/farm_stats_test.go
T
2026-08-17 21:43:26 +08:00

27 lines
879 B
Go

package service
import "testing"
func TestAggregateProductionLoss(t *testing.T) {
rows := []ProductionLossRow{
{RoomID: "room-a", DeathCount: 10, CulledCount: 2, YieldKg: 5, LossKg: 1, CostAmount: 20, RecordCount: 1},
{RoomID: "room-a", DeathCount: 3, CulledCount: 1, YieldKg: 2, LossKg: 0.5, CostAmount: 30, RecordCount: 1},
}
stats := AggregateProductionLoss(rows)
if len(stats) != 1 {
t.Fatalf("stats len = %d, want 1", len(stats))
}
if stats[0].DeathCount != 13 || stats[0].CulledCount != 3 || stats[0].CostAmount != 50 {
t.Fatalf("unexpected aggregate: %+v", stats[0])
}
if stats[0].RecordCount != 2 {
t.Fatalf("record count = %d, want 2", stats[0].RecordCount)
}
}
func TestAggregateProductionLossEmpty(t *testing.T) {
if stats := AggregateProductionLoss(nil); len(stats) != 0 {
t.Fatalf("empty input should return empty, got %d", len(stats))
}
}