예제 #1
0
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)
}
예제 #2
0
func TestNewPlayer(t *testing.T) {
	name := "player 1"
	p := foosbot.NewPlayer(name)
	assert.Equal(t, foosbot.BuildPlayerID(name), p.ID)
	assert.Equal(t, foosbot.BuildPlayerID(name)[:8], p.ShortID())
	assert.Equal(t, name, p.Name)
}
예제 #3
0
func randomPlayers(n int) []*foosbot.Player {
	players := []*foosbot.Player{}
	i := 0
	for i < 4 {
		n := rand.Intn(4)
		name := string(letters[i][n])
		players = append(players, foosbot.NewPlayer(name))
		i++
	}
	return players
}
예제 #4
0
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)
}