def test3(self): # # Three 5 seats tables (0, 1, 2) # table 0 : 2 players # table 1 : 5 players (running) # table 2 : 5 players (running) # games = self.games[:3] games[0].serial2player = {} games[0].max_players = 5 for serial in (1, 2): games[0].serial2player[serial] = None games[1].serial2player = {} games[1].max_players = 5 games[1].state = "turn" for serial in (100, 101, 102, 103, 104): games[1].serial2player[serial] = None games[2].serial2player = {} games[2].max_players = 5 games[2].state = "turn" for serial in (200, 201, 202, 203, 204): games[2].serial2player[serial] = None # # Games that could provide players are running and can't # provide players. Nothing can be done. # self.assertEqual(equalizeGames(games), []) # # Three 5 seats tables (0, 1, 2) # table 0 : 2 players (running) # table 1 : 5 players (running) # table 2 : 5 players # games[0].state = "turn" games[2].state = "end" # # Game 2 provide 2 players to game 0 # self.assertEqual(equalizeGames(games), [(2, 0, 200), (2, 0, 201)])
def test2(self): # # Two 5 seats tables (0, 1) # table 0 : 2 players # table 1 : 5 players # games = self.games[:2] games[0].serial2player = {} games[0].max_players = 5 for serial in (1, 2): games[0].serial2player[serial] = None games[1].serial2player = {} games[1].max_players = 5 for serial in (100, 101, 102, 103, 104): games[1].serial2player[serial] = None self.assertEqual(equalizeGames(games), [(1, 0, 100), (1, 0, 101)])
def test1(self): """ """ # # Five 10 seats tables (0 to 4) # table 0 : 8 players # table 1 : 8 players # table 2 : 7 players # table 3 : 7 players # table 4 : 2 players # counts = [8, 8, 7, 7, 2] for game in self.games: game.serial2player = {} for serial in xrange(counts.pop(0)): game.serial2player[game.id * 100 + serial] = None # # 2 players move # # table 0 : 8 players -> 1 leave to table 4 # table 1 : 8 players -> 1 leave to table 4 # table 2 : 7 players # table 3 : 7 players # table 4 : 2 players <- 2 arrive from table 0 and 1 # self.assertEqual(equalizeGames(self.games[:]), [(0, 4, 0), (1, 4, 100)]) # # Five 10 seats tables (0 to 4) # table 0 : 10 players # table 1 : 8 players # table 2 : 3 players # table 3 : 9 players # table 4 : 5 players # counts = [10, 8, 3, 9, 5] for game in self.games: game.serial2player = {} for serial in xrange(counts.pop(0)): game.serial2player[game.id * 100 + serial] = None # # 6 players move # # table 0 : 10 players -> 3 leave (2 to table 2, 1 to table 4) # table 1 : 8 players -> 1 leave (to table 2) # table 2 : 3 players <- 4 arrive (2 from table 0, 1 from table 2, 1 from table 3) # table 3 : 9 players -> 2 leave (1 to table 2, 1 to table 4) # table 4 : 5 players <- 2 arrive (1 from table 0, 1 from table 3) # self.assertEqual(equalizeGames(self.games[:]), [ (0, 4, 0), (0, 2, 1), (0, 4, 2), (1, 2, 100), (3, 4, 300), (3, 2, 301)]) # # Five 10 seats tables (0 to 4) # table 0 : 10 players # table 1 : 10 players # table 2 : 10 players # table 3 : 10 players # table 4 : 10 players # counts = [10, 10, 10, 10, 10] for game in self.games: game.serial2player = {} for serial in xrange(counts.pop(0)): game.serial2player[game.id * 100 + serial] = None # # Nothing to be done # self.assertEqual(equalizeGames(self.games[:]), [])