Ejemplo n.º 1
0
func load() {
	if len(config.years) == 0 {
		config.years = intslice(FirstYear, LastYear)
	}
	lahman.Load(config.years...)
	config.playerS = loadyears()
}
Ejemplo n.º 2
0
func Test_GetYear_PrintBatter(t *testing.T) {
	lahman.Load(2014)
	players := lahman.GetYear(2014)

	//for _, p := range players {
	//	fmt.Println(p.Year(), p.Name(), p.Bat, p.Pit)
	//}

	t.Log("Players in 2014", len(players))

	p := players[42] // Oswaldo Arcia
	t.Log(p.Name(), "should be Oswaldo Arcia")
	switch {
	case p.Bat.PA() != 410:
		fallthrough
	case p.Bat.G() != 103:
		fallthrough
	case p.Bat.AB() != 372:
		fallthrough
	case p.Bat.R() != 46:
		fallthrough
	case p.Bat.H() != 86:
		fallthrough
	case p.Bat.H2() != 16:
		fallthrough
	case p.Bat.H3() != 3:
		fallthrough
	case p.Bat.HR() != 20:
		fallthrough
	case p.Bat.RBI() != 57:
		fallthrough
	case p.Bat.SB() != 1:
		fallthrough
	case p.Bat.CS() != 2:
		fallthrough
	case p.Bat.BB() != 31:
		fallthrough
	case p.Bat.SO() != 127:
		fallthrough
	case p.Bat.IBB() != 4:
		fallthrough
	case p.Bat.HBP() != 6:
		fallthrough
	case p.Bat.SH() != 0:
		fallthrough
	case p.Bat.SF() != 1:
		fallthrough
	case p.Bat.GIDP() != 6:
		t.Fatal("Error printing one of Oswaldo's stats")
	default:
		t.Log("Oswaldo printed fine.")
	}
}
Ejemplo n.º 3
0
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!")
	}
}
Ejemplo n.º 4
0
func Test_GetYear_PrintPitcher(t *testing.T) {
	lahman.Load(2014)
	players := lahman.GetYear(2014)

	t.Log("Players in 2014", len(players))
	p := players[0] // Fernando Abad
	t.Log(p.Name(), "should be Abad")

	switch {
	case p.Pit.W() != 2:
		fallthrough
	case p.Pit.L() != 4:
		fallthrough
	case p.Pit.G() != 69:
		fallthrough
	case p.Pit.GS() != 0:
		fallthrough
	case p.Pit.CG() != 0:
		fallthrough
	case p.Pit.SHO() != 0:
		fallthrough
	case p.Pit.SV() != 0:
		fallthrough
	case p.Pit.IPouts() != 172:
		fallthrough
	case p.Pit.H() != 34:
		fallthrough
	case p.Pit.ER() != 10:
		fallthrough
	case p.Pit.HR() != 4:
		fallthrough
	case p.Pit.BB() != 15:
		fallthrough
	case p.Pit.SO() != 51:
		fallthrough
	case p.Pit.BAopp() != .175:
		fallthrough
	case p.Pit.ERA() != 1.57:
		fallthrough
	case p.Pit.IBB() != 3:
		fallthrough
	case p.Pit.WP() != 0:
		fallthrough
	case p.Pit.HBP() != 4:
		fallthrough
	case p.Pit.BK() != 0:
		fallthrough
	case p.Pit.BFP() != 216:
		fallthrough
	case p.Pit.GF() != 17:
		fallthrough
	case p.Pit.R() != 11:
		fallthrough
	case p.Pit.SH() != 1:
		fallthrough
	case p.Pit.SF() != 2:
		fallthrough
	case p.Pit.GIDP() != 6:
		t.Fatal("Error printing one of Abad's stats")
	default:
		t.Log("Abad printed fine.")
	}
}