def test_start_match(self): stdout = [] def mock_print(str="", *args, **kwargs): print(str) stdout.append(str) teams = { "first_id": "StoppingPlayer", "second_id": "SmartEatingPlayer", } config = MagicMock() config.rounds = 300 config.team_spec = lambda x: teams[x] config.team_name = lambda x: teams[x] config.viewer = 'ascii' config.filter = 'small' config.print = mock_print config.tournament_log_folder = None team_ids = ["first_id", "first_id"] result = tournament.start_match(config, team_ids) assert result == False assert stdout[-1] == '‘StoppingPlayer’ and ‘StoppingPlayer’ had a draw.' team_ids = ["second_id", "first_id"] result = tournament.start_match(config, team_ids) assert result == "second_id" assert stdout[-1] == '‘SmartEatingPlayer’ wins' team_ids = ["first_id", "second_id"] result = tournament.start_match(config, team_ids) assert result == "second_id" assert stdout[-1] == '‘SmartEatingPlayer’ wins'
def test_start_match(self): stdout = [] def mock_print(str="", *args, **kwargs): print(str) stdout.append(str) teams = { "first_id": "pelita/player/StoppingPlayer", "second_id": "pelita/player/SmartEatingPlayer", } config = MagicMock() config.rounds = 300 config.team_spec = lambda x: teams[x] config.team_name = lambda x: teams[x] config.viewer = 'ascii' config.filter = 'small' config.print = mock_print config.tournament_log_folder = None team_ids = ["first_id", "first_id"] result = tournament.start_match(config, team_ids) assert result == False assert stdout[-1] == '‘pelita/player/StoppingPlayer’ and ‘pelita/player/StoppingPlayer’ had a draw.' team_ids = ["second_id", "first_id"] result = tournament.start_match(config, team_ids) assert result == "second_id" assert stdout[-1] == '‘pelita/player/SmartEatingPlayer’ wins' team_ids = ["first_id", "second_id"] result = tournament.start_match(config, team_ids) assert result == "second_id" assert stdout[-1] == '‘pelita/player/SmartEatingPlayer’ wins'
def test_tournament_winner(self): stdout = [] def mock_print(str="", *args, **kwargs): stdout.append(str) c = { "location": None, "date": None, "bonusmatch": None, "teams": [ {"id": "group0", "spec": "StoppingPlayer", "members": []}, {"id": "group1", "spec": "SmartEatingPlayer", "members": []}, {"id": "group2", "spec": "StoppingPlayer", "members": []}, {"id": "group3", "spec": "StoppingPlayer", "members": []}, {"id": "group4", "spec": "StoppingPlayer", "members": []}, ], "filter": "small", } config = tournament.Config(c) config.print = mock_print config.viewer = 'null' config.state = None config.tournament_log_folder = None # group1 should win assert "group1" == tournament.start_match(config, ["group0", "group1"]) assert "group1" == tournament.start_match(config, ["group1", "group0"]) assert False == tournament.start_match(config, ["group0", "group0"]) tournament.present_teams(config) state = tournament.State(config) rr_ranking = tournament.round1(config, state) if config.bonusmatch: sorted_ranking = komode.sort_ranks(rr_ranking[:-1]) + [rr_ranking[-1]] else: sorted_ranking = komode.sort_ranks(rr_ranking) winner = tournament.round2(config, sorted_ranking, state) assert winner == 'group1'
def test_tournament_winner(self): stdout = [] def mock_print(str="", *args, **kwargs): stdout.append(str) c = { "location": None, "date": None, "bonusmatch": None, "teams": [ {"id": "group0", "spec": "pelita/player/StoppingPlayer", "members": []}, {"id": "group1", "spec": "pelita/player/SmartEatingPlayer", "members": []}, {"id": "group2", "spec": "pelita/player/StoppingPlayer", "members": []}, {"id": "group3", "spec": "pelita/player/StoppingPlayer", "members": []}, {"id": "group4", "spec": "pelita/player/StoppingPlayer", "members": []}, ], "filter": "small", } config = tournament.Config(c) config.print = mock_print config.viewer = 'null' config.state = None config.tournament_log_folder = None # group1 should win assert "group1" == tournament.start_match(config, ["group0", "group1"]) assert "group1" == tournament.start_match(config, ["group1", "group0"]) assert False == tournament.start_match(config, ["group0", "group0"]) tournament.present_teams(config) state = tournament.State(config) rr_ranking = tournament.round1(config, state) if config.bonusmatch: sorted_ranking = komode.sort_ranks(rr_ranking[:-1]) + [rr_ranking[-1]] else: sorted_ranking = komode.sort_ranks(rr_ranking) winner = tournament.round2(config, sorted_ranking, state) assert winner == 'group1'