func randomOutcomes(n int) []*foosbot.Outcome { outcomes := []*foosbot.Outcome{} for n > 0 { players := randomPlayers(4) rin := rand.Perm(4) t1, _ := foosbot.NewTeam(players[rin[0]], players[rin[1]]) t2, _ := foosbot.NewTeam(players[rin[2]], players[rin[3]]) outcome, _ := foosbot.NewOutcome(t1, t2) outcomes = append(outcomes, outcome) n-- } return outcomes }
func TestNewTeam(t *testing.T) { p1, p2 := foosbot.NewPlayer("p1"), foosbot.NewPlayer("p2") team, err := foosbot.NewTeam(p1, p2) assert.Nil(t, err) assert.Equal(t, foosbot.BuildTeamID(p2, p1), team.ID) assert.Equal(t, foosbot.BuildTeamID(p1, p2)[:8], team.ShortID()) assert.Equal(t, []*foosbot.Player{p1, p2}, team.Players) }
func TestNewTeamWithDuplicatedPlayers(t *testing.T) { p1, p2 := foosbot.NewPlayer("a"), foosbot.NewPlayer("a") team, err := foosbot.NewTeam(p1, p2) assert.Nil(t, team) assert.Equal(t, err, foosbot.ErrTeamDuplicatePlayer) }
func TestNewTeamWithoutPlayers(t *testing.T) { team, err := foosbot.NewTeam() assert.Nil(t, team) assert.Equal(t, foosbot.ErrTeamNoPlayers, err) }