def test_odds_even_for_equal_elos(self):
        team_1 = team.Team(name=1, conference=1, division=1)
        team_2 = team.Team(name=2, conference=1, division=1)

        subject = game.Game(home_team=team_1, away_team=team_2)

        self.assertEqual(.5, subject.home_team_win_probability())
    def test_odds_unfavorable_for_unfavored_team(self):
        team_1 = team.Team(name=1, elo=1300, conference=1, division=1)
        team_2 = team.Team(name=2, elo=1400, conference=1, division=1)

        subject = game.Game(home_team=team_1, away_team=team_2)

        self.assertLess(subject.home_team_win_probability(), .5)
    def test_unfavored_team(self):
        team_1 = team.Team(name=1, elo=1300, conference=1, division=1)
        team_2 = team.Team(name=2, elo=1400, conference=1, division=1)

        subject = game.Game(home_team=team_1, away_team=team_2)
        favored_team = subject.unfavored_team()
        self.assertEqual(favored_team.name, team_1.name)

        subject = game.Game(home_team=team_2, away_team=team_1)
        favored_team = subject.unfavored_team()
        self.assertEqual(favored_team.name, team_1.name)
    def test_choose_winner(self):
        team_1 = team.Team(name=1, elo=1300, conference=1, division=1)
        team_2 = team.Team(name=2, elo=1400, conference=1, division=1)

        subject = game.Game(home_team=team_1, away_team=team_2)

        winner = subject.choose_winner(subject.home_team_win_probability() / 2)

        self.assertTrue(winner.name == 1)

        winner = subject.choose_winner(1 -
                                       (subject.home_team_win_probability() /
                                        2))

        self.assertTrue(winner.name == 2)
    def test_favor_favored_teams(self):
        subject = randomly_choose_favored_team.RandomlyChooseFavoredTeam()

        team_1 = team.Team(name=1, conference=1, division=1, elo=1100)
        team_2 = team.Team(name=2, conference=2, division=2, elo=1200)
        team_3 = team.Team(name=3, conference=3, division=3, elo=1300)
        team_4 = team.Team(name=4, conference=4, division=4, elo=1400)
        teams = [team_1, team_2, team_3, team_4]
        home_teams = teams[:int((len(teams)/2))]
        away_teams = teams[int(len(teams)/2):]
        games = [game.Game(home_team=h, away_team=a) for h, a in zip(home_teams, away_teams)]

        ranked_teams = subject.rank_teams(games, [])

        self.assertTrue(team_4 in ranked_teams[:2])
    def test_favor_most_favored_team(self):
        subject = choose_most_favored_team.ChooseMostFavoredTeam()

        team_1 = team.Team(name=1, conference=1, division=1, elo=1100)
        team_2 = team.Team(name=2, conference=2, division=2, elo=1200)
        team_3 = team.Team(name=3, conference=3, division=3, elo=1350)
        team_4 = team.Team(name=4, conference=4, division=4, elo=1400)
        teams = [team_1, team_2, team_3, team_4]
        home_teams = teams[:int((len(teams)/2))]
        away_teams = teams[int(len(teams)/2):]
        games = [game.Game(home_team=h, away_team=a) for h, a in zip(home_teams, away_teams)]

        ranked_teams = subject.rank_teams(games, [])

        self.assertListEqual(ranked_teams, [team_3, team_4, team_2, team_1])
    def test_ignore_ineligible_teams(self):
        subject = choose_most_favored_team.ChooseMostFavoredTeam()

        team_1 = team.Team(name=1, conference=1, division=1, elo=1100)
        team_2 = team.Team(name=2, conference=2, division=2, elo=1200)
        team_3 = team.Team(name=3, conference=3, division=3, elo=1300)
        team_4 = team.Team(name=4, conference=4, division=4, elo=1400)
        teams = [team_1, team_2, team_3, team_4]
        home_teams = teams[:int((len(teams) / 2))]
        away_teams = teams[int(len(teams) / 2):]
        games = [game.Game(home_team=h, away_team=a) for h, a in zip(home_teams, away_teams)]

        ranked_teams = subject.rank_teams(games, [1, 4])

        self.assertEqual(len(ranked_teams), 2)
        self.assertTrue(team_4 not in ranked_teams)
        self.assertEqual(ranked_teams[0], team_3)
    def _generate_teams(self):
        teams = list()

        for c in range(self.num_conferences):
            for d in range(self.num_divisions):
                for t in range(self.num_teams):
                    teams.append(team.Team(conference=c, division=d, name=f"{c}-{d}-{t}",
                                           elo=random.uniform(1250, 1750)))

        return teams
    def test_choose_team(self):
        subject = player.Player(name=0,
                                strategy=choose_randomly.ChooseRandomly())

        teams = [team.Team(name=t, division=t, conference=t) for t in range(4)]
        games = [
            game.Game(home_team=t1, away_team=t2)
            for t1, t2 in zip(teams[:int(len(teams) /
                                         2)], teams[int(len(teams) / 2):])
        ]

        choice = subject.choose_team(games)

        self.assertTrue(len([t for t in teams if t.name == choice]) == 1)
        self.assertTrue(choice in subject._teams_chosen)
        self.assertTrue(subject.have_chosen_team(choice))
示例#10
0
    def generate_subject_teams_games_choice_count(num_eligible_teams,
                                                  num_ineligible_teams=0):
        subject = choose_randomly.ChooseRandomly()

        teams = [
            team.Team(name=n, conference=1, division=1)
            for n in range(num_eligible_teams + num_ineligible_teams)
        ]
        home_teams = teams[:int((len(teams) / 2))]
        away_teams = teams[int(len(teams) / 2):]
        games = [
            game.Game(home_team=h, away_team=a)
            for h, a in zip(home_teams, away_teams)
        ]

        team_choice_count = {}
        for t in teams:
            team_choice_count[t.name] = 0

        return subject, teams, games, team_choice_count
示例#11
0
    def test_set_elo(self):
        expected_elo = 1400

        subject = team.Team(elo=expected_elo, name=1, conference=1, division=1)

        self.assertEqual(expected_elo, subject.elo)
示例#12
0
    def test_fall_back_to_default_elo(self):
        expected_elo = team.DEFAULT_ELO

        subject = team.Team(name=1, conference=1, division=1)

        self.assertEqual(expected_elo, subject.elo)