▍ humdrum codex / sportsball
license AGPL-3.0
1.2 KB raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)
	}
}