func loadyears() (ps playerS) { for _, y := range config.years { var playerYears playerS if config.post { playerYears = lahman.GetPostYear(y) } else { playerYears = lahman.GetYear(y) } for _, p := range playerYears { ps = append(ps, p) } } return ps }
func Test_GetPostYear(t *testing.T) { players := lahman.GetPostYear(2010) none := true for _, p := range players { if p.Pit.SHO() > 0 && p.Pit.H() == 0 { // Roy Halladay 2010 none = false if p.Year() != 2010 { t.Log(p.Year()) t.Fatal("Year should be 2010") } if p.Stint() != "NLDS1" { t.Log(p.Stint()) t.Fatal("Stint should be NLDS1") } } } if none { t.Fatal("Halladay isn't there") } }
func Test_GetYear(t *testing.T) { years := []int{} for i := 1871; i < 2015; i++ { years = append(years, i) } lahman.Load(years...) count := 0 for i := 1871; i < 2015; i++ { players := lahman.GetPostYear(i) for _, p := range players { if p.Pit.SHO() > 0 && p.Pit.H() == 0 { //fmt.Println(p) count++ } } } if count != 1 { t.Log("World series shutouts in history: ", count) t.Fatal("there should be only one world series shutout in history!") } }