func TestNewOutcome(t *testing.T) { winner, looser := newTeam("team a"), newTeam("team b") outcome, err := foosbot.NewOutcome(winner, looser) assert.Nil(t, err) assert.Equal(t, foosbot.BuildOutcomeID(winner, looser), outcome.ID) assert.Equal(t, foosbot.BuildOutcomeID(winner, looser)[:8], outcome.ShortID()) assert.Equal(t, outcome.WinnerID, winner.ID) assert.Equal(t, outcome.LooserID, looser.ID) assert.Equal(t, 0, outcome.Occurrences) assert.True(t, outcome.IsWinner(winner)) assert.True(t, outcome.IsLooser(looser)) }
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 TestNewOutcomeDuplicated(t *testing.T) { winner, looser := newTeam("team a"), newTeam("team a") outcome, err := foosbot.NewOutcome(winner, looser) assert.Nil(t, outcome) assert.Equal(t, err, foosbot.ErrOutcomeImpossible) }