コード例 #1
0
ファイル: factory_test.go プロジェクト: huanshi/AssassinWar
func TestNewGame(t *testing.T) {
	game := NewGame()
	testUtil.AssertEqual(0, game.GetPlayerCount(), "TestNewGame", t)
	testUtil.AssertEqual(1, game.GetId(), "TestNewGame", t)

	game = NewGame()
	testUtil.AssertEqual(0, game.GetPlayerCount(), "TestNewGame", t)
	testUtil.AssertEqual(2, game.GetId(), "TestNewGame", t)
}
コード例 #2
0
func TestJoinGame(t *testing.T) {
	manager := game.GetPlayerManagerInstance()
	manager.RemoveAllPlayer()

	players := joinGame("linwei", "gameId")
	testUtil.AssertEqual(1, manager.GetPlayerCount(), "TestJoinGame", t)
	testUtil.AssertEqual(1, len(players), "TestJoinGame", t)
	testUtil.AssertEqual("linwei", players[0].GetName(), "TestJoinGame", t)
}
コード例 #3
0
ファイル: game_test.go プロジェクト: huanshi/AssassinWar
func TestQuitGame(t *testing.T) {
	game := NewGame()
	player := NewPlayer("worge", 0, 0)
	game.Join(player)
	testUtil.AssertEqual(1, game.GetPlayerCount(), "TestJoinGame", t)

	game.Quit("worge")
	testUtil.AssertEqual(0, game.GetPlayerCount(), "TestJoinGame", t)
}
コード例 #4
0
ファイル: player_test.go プロジェクト: huanshi/AssassinWar
func TestGetSetPos(t *testing.T) {
	player := NewPlayer("name", 1, 1)
	testUtil.AssertEqual(1, player.GetPosX(), "TestGetSetPos", t)
	testUtil.AssertEqual(1, player.GetPosY(), "TestGetSetPos", t)

	player.PosX = 3
	player.PosY = 2
	testUtil.AssertEqual(3, player.GetPosX(), "TestGetSetPos", t)
	testUtil.AssertEqual(2, player.GetPosY(), "TestGetSetPos", t)
}
コード例 #5
0
ファイル: player_test.go プロジェクト: huanshi/AssassinWar
func TestGetToSendMsgChan(t *testing.T) {
	player := NewPlayer("name", 1, 1)
	go sendMsgToPlayer(player)
	select {
	case msg := <-player.toSendMsgChan:
		testUtil.AssertEqual("type", msg.Type, "TestGetToSendMsgChan", t)
		testUtil.AssertEqual("worge", msg.From, "TestGetToSendMsgChan", t)
		testUtil.AssertEqual("content", msg.Content, "TestGetToSendMsgChan", t)
	case <-time.After(5 * time.Second):
		t.Fail()
	}
}
コード例 #6
0
func TestRemovePlayer(t *testing.T) {
	manager := GetPlayerManagerInstance()
	manager.RemoveAllPlayer()

	testUtil.AssertEqual(0, manager.GetPlayerCount(), "TestAddPlayer", t)

	player1 := NewPlayer("name1", 0, 0)
	manager.AddPlayer(player1)
	testUtil.AssertEqual(1, manager.GetPlayerCount(), "TestAddPlayer", t)

	manager.RemovePlayer("name1")
	testUtil.AssertEqual(0, manager.GetPlayerCount(), "TestAddPlayer", t)
}
コード例 #7
0
func TestGetPlayerCount(t *testing.T) {
	manager := GetPlayerManagerInstance()
	manager.RemoveAllPlayer()

	testUtil.AssertEqual(0, manager.GetPlayerCount(), "TestGetPlayerCount", t)

	player1 := NewPlayer("n1", 0, 0)
	manager.AddPlayer(player1)
	testUtil.AssertEqual(1, manager.GetPlayerCount(), "TestGetPlayerCount", t)

	player2 := NewPlayer("n2", 0, 0)
	manager.AddPlayer(player2)
	testUtil.AssertEqual(2, manager.GetPlayerCount(), "TestGetPlayerCount", t)
}
コード例 #8
0
func TestGetPlayer(t *testing.T) {
	manager := GetPlayerManagerInstance()
	manager.RemoveAllPlayer()

	player1 := NewPlayer("n1", 0, 0)
	manager.AddPlayer(player1)
	findPlayer := manager.GetPlayer("n1")
	testUtil.AssertEqual("n1", findPlayer.GetName(), "TestAddPlayer", t)

	player2 := NewPlayer("n2", 0, 0)
	manager.AddPlayer(player2)
	findPlayer = manager.GetPlayer("n2")
	testUtil.AssertEqual("n2", findPlayer.GetName(), "TestAddPlayer", t)
}
コード例 #9
0
ファイル: game_test.go プロジェクト: huanshi/AssassinWar
func TestBroadcastMsg(t *testing.T) {
	game := NewGame()
	player := NewPlayer("worge", 0, 0)
	game.Join(player)
	testUtil.AssertEqual(1, game.GetPlayerCount(), "TestBroadcastMsg", t)

	player2 := NewPlayer("linwei", 0, 0)
	game.Join(player2)
	testUtil.AssertEqual(2, game.GetPlayerCount(), "TestBroadcastMsg", t)

	newMsgs := player.getNewMsgs()
	testUtil.AssertEqual(1, len(newMsgs), "TestBroadcastMsg", t)
	testUtil.AssertEqual("linwei", newMsgs[0].From, "TestBroadcastMsg", t)
	testUtil.AssertEqual("joinGame", newMsgs[0].Type, "TestBroadcastMsg", t)
}
コード例 #10
0
ファイル: game_test.go プロジェクト: huanshi/AssassinWar
func TestGetAllPlayerForGame(t *testing.T) {
	game := NewGame()
	testUtil.AssertEqual(0, len(game.GetAllPlayer()), "TestGetAllPlayerForGame", t)

	player := NewPlayer("worge", 0, 0)
	game.Join(player)
	testUtil.AssertEqual(1, len(game.GetAllPlayer()), "TestGetAllPlayerForGame", t)

	player2 := NewPlayer("worge", 0, 0)
	game.Join(player2)
	testUtil.AssertEqual(1, len(game.GetAllPlayer()), "TestGetAllPlayerForGame", t)

	player3 := NewPlayer("linwei", 0, 0)
	game.Join(player3)
	testUtil.AssertEqual(2, len(game.GetAllPlayer()), "TestGetAllPlayerForGame", t)
}
コード例 #11
0
func TestGetAllPlayer(t *testing.T) {
	playerManager := game.GetPlayerManagerInstance()
	playerManager.RemoveAllPlayer()

	player := game.NewPlayer("na1", 0, 0)
	playerManager.AddPlayer(player)

	jsonContent := getAllPlayer()
	testUtil.AssertEqual("[{\"Name\":\"na1\",\"PosX\":0,\"PosY\":0}]", jsonContent, "TestGetJson", t)

	player2 := game.NewPlayer("na2", 2, 2)
	playerManager.AddPlayer(player2)

	jsonContent = getAllPlayer()
	testUtil.AssertEqual("[{\"Name\":\"na1\",\"PosX\":0,\"PosY\":0},{\"Name\":\"na2\",\"PosX\":2,\"PosY\":2}]", jsonContent, "TestGetJson", t)

}
コード例 #12
0
func TestGetAllPlayer(t *testing.T) {
	manager := GetPlayerManagerInstance()
	manager.RemoveAllPlayer()

	allPlayers := manager.GetAllPlayer()
	testUtil.AssertEqual(0, len(allPlayers), "TestGetAllPlayer", t)

	player1 := NewPlayer("n1", 0, 0)
	manager.AddPlayer(player1)
	allPlayers = manager.GetAllPlayer()
	testUtil.AssertEqual(1, len(allPlayers), "TestGetAllPlayer", t)
	testUtil.AssertEqual("n1", allPlayers[0].GetName(), "TestGetAllPlayer", t)

	player2 := NewPlayer("n2", 0, 0)
	manager.AddPlayer(player2)
	allPlayers = manager.GetAllPlayer()
	testUtil.AssertEqual(2, len(allPlayers), "TestGetAllPlayer", t)
	testUtil.AssertEqual("n2", allPlayers[1].GetName(), "TestGetAllPlayer", t)
}
コード例 #13
0
ファイル: game_test.go プロジェクト: huanshi/AssassinWar
func TestJoinGame(t *testing.T) {
	game := NewGame()
	player := NewPlayer("worge", 0, 0)
	game.Join(player)
	testUtil.AssertEqual(1, game.GetPlayerCount(), "TestJoinGame", t)
	testUtil.AssertEqual("worge", game.GetPlayer("worge").GetName(), "TestJoinGame", t)

	player2 := NewPlayer("linwei", 0, 0)
	game.Join(player2)
	testUtil.AssertEqual(2, game.GetPlayerCount(), "TestJoinGame", t)
	testUtil.AssertEqual("worge", game.GetPlayer("worge").GetName(), "TestJoinGame", t)

	player3 := NewPlayer("worge", 0, 0)
	game.Join(player3)
	testUtil.AssertEqual(2, game.GetPlayerCount(), "TestJoinGame", t)
	testUtil.AssertEqual("worge", game.GetPlayer("worge").GetName(), "TestJoinGame", t)
}
コード例 #14
0
func TestAddGame(t *testing.T) {
	game := NewGame()
	manager := GetGameManagerInstance()
	manager.AddGame(game)
	testUtil.AssertEqual(1, manager.GetGameCount(), "TestAddGame", t)
}
コード例 #15
0
func TestGetGame(t *testing.T) {
	game := NewGame()
	manager := GetGameManagerInstance()
	manager.AddGame(game)
	testUtil.AssertEqual(game.GetId(), manager.GetGame(game.GetId()).GetId(), "TestGetGame", t)
}