package espn import ( "testing" ) // mapTeamStats pairs home/away flat stats into curated, ordered comparison rows // and skips stats absent from both sides. func TestMapTeamStats(t *testing.T) { teams := []teamStatBox{ {HomeAway: "home", Statistics: []teamStatJSON{ {Name: "possessionPct", Label: "Possession", DisplayValue: "48.4"}, {Name: "totalShots", Label: "SHOTS", DisplayValue: "9"}, }}, {HomeAway: "away", Statistics: []teamStatJSON{ {Name: "possessionPct", Label: "Possession", DisplayValue: "51.6"}, {Name: "totalShots", Label: "SHOTS", DisplayValue: "4"}, }}, } got := mapTeamStats(teams) if len(got) != 2 { t.Fatalf("want 2 stats (only present keys), got %d: %+v", len(got), got) } if got[0].Key != "possessionPct" || got[0].Away != "51.6" || got[0].Home != "48.4" { t.Errorf("row0 = %+v", got[0]) } if got[1].Label != "SHOTS" || got[1].Away != "4" || got[1].Home != "9" { t.Errorf("row1 = %+v", got[1]) } } // Without both home and away present, there's nothing to compare. func TestMapTeamStatsNeedsBothSides(t *testing.T) { if got := mapTeamStats([]teamStatBox{{HomeAway: "home"}}); got != nil { t.Errorf("one-sided stats should map to nil, got %+v", got) } }