當前位置: 首頁>>代碼示例>>Golang>>正文


Golang testhelpers.CreatePlayer函數代碼示例

本文整理匯總了Golang中github.com/TF2Stadium/Helen/internal/testhelpers.CreatePlayer函數的典型用法代碼示例。如果您正苦於以下問題:Golang CreatePlayer函數的具體用法?Golang CreatePlayer怎麽用?Golang CreatePlayer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了CreatePlayer函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestHasPlayer

func TestHasPlayer(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	defer lobby.Close(false)
	player := testhelpers.CreatePlayer()

	lobby.AddPlayer(player, 1, "")
	assert.True(t, lobby.HasPlayer(player))

	player2 := testhelpers.CreatePlayer()
	assert.False(t, lobby.HasPlayer(player2))

	lobby.RemovePlayer(player)
	assert.False(t, lobby.HasPlayer(player))
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:15,代碼來源:lobby_test.go

示例2: TestMatchEnded

func TestMatchEnded(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	player := testhelpers.CreatePlayer()

	lobby.Type = models.LobbyTypeBball
	lobby.Save()
	lobby.AddPlayer(player, 0, "")

	e := rpc.Event{
		Name:    rpc.MatchEnded,
		LobbyID: lobby.ID,
	}

	e.Handle(e, &struct{}{})
	db.DB.Preload("Stats").First(player, player.ID)
	assert.Equal(t, player.Stats.PlayedBballCount, 1)

	lobby = testhelpers.CreateLobby()

	lobby.Type = models.LobbyTypeBball
	lobby.Save()
	lobby.AddPlayer(player, 0, "")

	e.LobbyID = lobby.ID
	e.Handle(e, &struct{}{})
	db.DB.Preload("Stats").First(player, player.ID)
	assert.Equal(t, player.Stats.PlayedBballCount, 2)
	assert.Equal(t, player.Stats.TotalLobbies(), 2)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:30,代碼來源:event_test.go

示例3: TestPlayerSettings

func TestPlayerSettings(t *testing.T) {
	t.Parallel()

	player := testhelpers.CreatePlayer()

	settings, err := player.GetSettings()

	assert.Nil(t, err)
	assert.Equal(t, 0, len(settings))

	err = player.SetSetting("foo", "bar")
	assert.Nil(t, err)

	settings, err = player.GetSettings()
	assert.Nil(t, err)
	assert.Equal(t, "foo", settings[0].Key)
	assert.Equal(t, "bar", settings[0].Value)

	setting, err := player.GetSetting("foo")
	assert.Nil(t, err)
	assert.Equal(t, "bar", setting.Value)

	err = player.SetSetting("hello", "world")
	assert.Nil(t, err)

	settings, err = player.GetSettings()
	assert.Nil(t, err)
	assert.Equal(t, 2, len(settings))
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:29,代碼來源:player_test.go

示例4: TestLobbyAdd

func TestLobbyAdd(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	defer lobby.Close(false)
	lobby.Save()

	var players []*Player

	for i := 0; i < 12; i++ {
		player := testhelpers.CreatePlayer()
		players = append(players, player)
	}

	// add player
	err := lobby.AddPlayer(players[0], 0, "")
	assert.Nil(t, err)

	slot, err2 := lobby.GetPlayerSlot(players[0])
	assert.Zero(t, slot)
	assert.Nil(t, err2)

	id, err3 := lobby.GetPlayerIDBySlot(0)
	assert.Equal(t, id, players[0].ID)
	assert.Nil(t, err3)

	// try to switch slots
	err = lobby.AddPlayer(players[0], 1, "")
	assert.Nil(t, err)

	slot, err2 = lobby.GetPlayerSlot(players[0])
	assert.Equal(t, slot, 1)
	assert.Nil(t, err2)

	// this should be empty now
	id, err3 = lobby.GetPlayerIDBySlot(0)
	assert.NotNil(t, err3)

	// try to add a second player to the same slot
	err = lobby.AddPlayer(players[1], 1, "")
	assert.NotNil(t, err)

	// try to add a player to a wrong slot slot
	err = lobby.AddPlayer(players[2], 55, "")
	assert.NotNil(t, err)

	lobby2 := testhelpers.CreateLobby()
	defer lobby.Close(false)
	lobby2.Save()

	// try to add a player while they're in another lobby
	//player should be substituted
	lobby.State = LobbyStateInProgress
	lobby.Save()
	err = lobby2.AddPlayer(players[0], 1, "")
	assert.Nil(t, err)

	var count int
	db.DB.Table("lobby_slots").Where("lobby_id = ? AND needs_sub = ?", lobby.ID, true).Count(&count)
	assert.Equal(t, count, 1)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:60,代碼來源:lobby_test.go

示例5: TestNotInGameSub

func TestNotInGameSub(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	defer lobby.Close(false)
	var (
		players                  []*Player
		ingame, subbed, subcount int
		//subs                     []int
	)

	for i := 0; i < 12; i++ {
		players = append(players, testhelpers.CreatePlayer())
	}
	for i, player := range players {
		err := lobby.AddPlayer(player, i, "")
		assert.NoError(t, err)
		r := rand.Intn(3)
		if r == 1 {
			ingame++
			lobby.SetInGame(player)
		} else if r == 2 {
			lobby.Substitute(player)
			subbed++
		}

	}

	t.Logf("%d players are in-game, %d player have been substituted", ingame, subbed)
	lobby.SubNotInGamePlayers()

	db.DB.Table("lobby_slots").Where("lobby_id = ? AND needs_sub = ?", lobby.ID, true).Count(&subcount)
	//assert.Equal(t, subcount, len(subs))
	lobby.Close(false)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:34,代碼來源:lobby_test.go

示例6: TestRemoveUnreadyPlayers

func TestRemoveUnreadyPlayers(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	defer lobby.Close(false)
	lobby.Save()

	var players []*Player
	for i := 0; i < 12; i++ {
		player := testhelpers.CreatePlayer()

		lobby.AddPlayer(player, i, "")
		players = append(players, player)
	}

	err := lobby.RemoveUnreadyPlayers(true)
	assert.Nil(t, err)

	for i := 0; i < 12; i++ {
		var count int
		_, err := lobby.GetPlayerIDBySlot(i)
		assert.Error(t, err)

		db.DB.Table("spectators_players_lobbies").Where("lobby_id = ? AND player_id = ?", lobby.ID, players[i].ID).Count(&count)
		assert.Equal(t, count, 1)
	}
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:26,代碼來源:lobby_test.go

示例7: TestGetLobbyID

func TestGetLobbyID(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	lobby.Save()

	player := testhelpers.CreatePlayer()
	player.Save()

	lobby.AddPlayer(player, 0, "")
	lobby.Save()

	id, err := player.GetLobbyID(false)
	assert.NoError(t, err)
	assert.Equal(t, id, lobby.ID)

	lobby.State = LobbyStateEnded
	lobby.Save()
	id, err = player.GetLobbyID(false)
	assert.Error(t, err)
	assert.Equal(t, id, uint(0))

	lobby.State = LobbyStateInProgress
	lobby.Save()

	//Exclude lobbies in progress
	id, err = player.GetLobbyID(true)
	assert.Error(t, err)
	assert.Equal(t, id, uint(0))

	//Include lobbies in progress
	id, err = player.GetLobbyID(false)
	assert.NoError(t, err)
	assert.Equal(t, id, lobby.ID)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:34,代碼來源:player_test.go

示例8: TestGetSpectatingIds

func TestGetSpectatingIds(t *testing.T) {
	t.Parallel()

	player := testhelpers.CreatePlayer()

	specIds, specErr := player.GetSpectatingIds()
	assert.Nil(t, specErr)
	assert.Equal(t, len(specIds), 0)
	//assert.Equal(t, []uint{lobby.ID, lobby2.ID}, specIds)

	lobby1 := testhelpers.CreateLobby()
	database.DB.Save(lobby1)
	lobby1.AddSpectator(player)

	specIds, specErr = player.GetSpectatingIds()
	assert.Nil(t, specErr)
	assert.Equal(t, specIds[0], lobby1.ID)

	lobby2 := testhelpers.CreateLobby()
	database.DB.Save(lobby2)
	lobby2.AddSpectator(player)

	specIds, specErr = player.GetSpectatingIds()
	assert.Nil(t, specErr)
	for _, specID := range specIds {
		assert.True(t, lobby1.ID == specID || lobby2.ID == specID)
	}
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:28,代碼來源:player_test.go

示例9: TestIsSpectating

func TestIsSpectating(t *testing.T) {
	t.Parallel()

	lobby := testhelpers.CreateLobby()
	database.DB.Save(lobby)

	lobby2 := testhelpers.CreateLobby()
	database.DB.Save(lobby2)

	player := testhelpers.CreatePlayer()

	isSpectating := player.IsSpectatingID(lobby.ID)
	assert.False(t, isSpectating)

	lobby.AddSpectator(player)

	isSpectating = player.IsSpectatingID(lobby.ID)
	assert.True(t, isSpectating)

	lobby2.AddSpectator(player)
	isSpectating2 := player.IsSpectatingID(lobby2.ID)
	assert.True(t, isSpectating2)

	lobby.RemoveSpectator(player, false)
	isSpectating = player.IsSpectatingID(lobby.ID)
	assert.False(t, isSpectating)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:27,代碼來源:player_test.go

示例10: TestGetPlayer

func TestGetPlayer(t *testing.T) {
	t.Parallel()
	player := testhelpers.CreatePlayer()
	player2, err := GetPlayerByID(player.ID)
	assert.NoError(t, err)
	assert.Equal(t, player.ID, player2.ID)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:7,代碼來源:player_test.go

示例11: TestSpectators

func TestSpectators(t *testing.T) {
	t.Parallel()

	player := testhelpers.CreatePlayer()

	player2 := testhelpers.CreatePlayer()

	lobby := testhelpers.CreateLobby()
	defer lobby.Close(false)
	lobby.Save()

	err := lobby.AddSpectator(player)
	assert.Nil(t, err)

	var specs []Player
	db.DB.Model(lobby).Association("Spectators").Find(&specs)
	assert.Equal(t, 1, len(specs))

	err = lobby.AddSpectator(player2)
	assert.Nil(t, err)

	specs = nil
	db.DB.Model(lobby).Association("Spectators").Find(&specs)
	assert.Equal(t, 2, len(specs))
	assert.Equal(t, true, specs[0].IsSpectatingID(lobby.ID))

	err = lobby.RemoveSpectator(player, false)
	assert.Nil(t, err)

	specs = nil
	db.DB.Model(lobby).Association("Spectators").Find(&specs)
	assert.Equal(t, 1, len(specs))

	// adding the same player again should not increase the count
	err = lobby.AddSpectator(player2)
	specs = nil
	db.DB.Model(lobby).Association("Spectators").Find(&specs)
	assert.Equal(t, 1, len(specs))

	// adding a player should remove them from spectators
	lobby.AddPlayer(player2, 11, "")
	specs = nil
	db.DB.Model(lobby).Association("Spectators").Find(&specs)
	assert.Zero(t, len(specs))
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:45,代碼來源:lobby_test.go

示例12: TestIsEveryoneReady

func TestIsEveryoneReady(t *testing.T) {
	t.Parallel()
	player := testhelpers.CreatePlayer()

	lobby := testhelpers.CreateLobby()
	defer lobby.Close(false)
	lobby.Save()
	lobby.AddPlayer(player, 0, "")
	lobby.ReadyPlayer(player)
	assert.Equal(t, lobby.IsEveryoneReady(), false)

	for i := 1; i < 12; i++ {
		player := testhelpers.CreatePlayer()
		lobby.AddPlayer(player, i, "")
		lobby.ReadyPlayer(player)
	}
	assert.Equal(t, lobby.IsEveryoneReady(), true)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:18,代碼來源:lobby_test.go

示例13: TestIsSubNeeded

func TestIsSubNeeded(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	defer lobby.Close(false)
	player := testhelpers.CreatePlayer()
	lobby.AddPlayer(player, 1, "")

	lobby.Substitute(player)
	assert.True(t, lobby.SlotNeedsSubstitute(1))

}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:11,代碼來源:lobby_test.go

示例14: TestSlotRequirements

func TestSlotRequirements(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	defer lobby.Close(false)
	player := testhelpers.CreatePlayer()
	req := &Requirement{
		LobbyID: lobby.ID,
		Slot:    0,
		Hours:   1,
		Lobbies: 1,
	}
	req.Save()

	assert.True(t, lobby.HasRequirements(0))
	err := lobby.AddPlayer(player, 0, "")
	assert.Equal(t, err, ReqHoursErr)

	player.GameHours = 2
	player.Save()

	err = lobby.AddPlayer(player, 0, "")
	assert.Equal(t, err, ReqLobbiesErr)

	player, _ = GetPlayerWithStats(player.SteamID)
	player.Stats.PlayedCountIncrease(lobby.Type)

	err = lobby.AddPlayer(player, 0, "")
	assert.NoError(t, err)

	//Adding a player to another slot shouldn't return any errors
	// req = &Requirement{
	// 	LobbyID: lobby.ID,
	// 	Slot:    -1,
	// 	Hours:   1,
	// 	Lobbies: 1,
	// }
	player2 := testhelpers.CreatePlayer()
	err = lobby.AddPlayer(player2, 1, "")
	assert.NoError(t, err)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:40,代碼來源:lobby_test.go

示例15: TestSetInGame

func TestSetInGame(t *testing.T) {
	t.Parallel()
	player := testhelpers.CreatePlayer()

	lobby := testhelpers.CreateLobby()
	defer lobby.Close(false)
	lobby.Save()
	lobby.AddPlayer(player, 0, "")
	lobby.SetInGame(player)

	slot, err := lobby.GetPlayerSlotObj(player)
	assert.Nil(t, err)
	assert.True(t, slot.InGame)
}
開發者ID:gpittarelli,項目名稱:Helen,代碼行數:14,代碼來源:lobby_test.go


注:本文中的github.com/TF2Stadium/Helen/internal/testhelpers.CreatePlayer函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。