def test_games_for_week(self):
        weeks = [
            week.Week(number=1, games=[game.Game(home_team=1, away_team=2)]),
            week.Week(number=2,
                      games=[
                          game.Game(home_team=3, away_team=4),
                          game.Game(home_team=5, away_team=6)
                      ])
        ]
        subject = schedule.Schedule(weeks=weeks)

        week_1 = subject.games_for_week(1)
        week_2 = subject.games_for_week(2)

        self.assertEqual(len(week_1), 1)
        self.assertEqual(len(week_2), 2)

        week_1_home = [g.home_team for g in week_1]
        week_1_away = [g.away_team for g in week_1]
        week_2_home = [g.home_team for g in week_2]
        week_2_away = [g.away_team for g in week_2]

        self.assertListEqual(week_1_home, [1])
        self.assertListEqual(week_1_away, [2])
        self.assertListEqual(week_2_home, [3, 5])
        self.assertListEqual(week_2_away, [4, 6])
    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_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 _generate_week(self, week_num, teams):
        random.shuffle(teams)
        non_bye_teams = self._filter_bye_teams(teams)

        home_teams = non_bye_teams[:int(len(non_bye_teams)/2)]
        away_teams = non_bye_teams[int(len(non_bye_teams)/2):]
        return week.Week(
            number=week_num,
            games=[game.Game(home_team=h, away_team=a) for h, a in zip(home_teams, away_teams)]
        )
    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_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))
    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)
Ejemplo n.º 11
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