def test_make_brackets_with_four_teams(self): gryffindor = hedger.Entry('Gryffindor', 100) ravenclaw = hedger.Entry('Ravenclaw', 100) hufflepuff = hedger.Entry('Hufflepuff', 100) slytherin = hedger.Entry('Slytherin', 100) entries = [gryffindor, ravenclaw, hufflepuff, slytherin] quidditch_cup = hedger.Tournament(entries) all_brackets = quidditch_cup.brackets all_results = [ [Result.BOTTOM_WINS, Result.BOTTOM_WINS, Result.BOTTOM_WINS], [Result.BOTTOM_WINS, Result.BOTTOM_WINS, Result.TOP_WINS], [Result.BOTTOM_WINS, Result.TOP_WINS, Result.BOTTOM_WINS], [Result.BOTTOM_WINS, Result.TOP_WINS, Result.TOP_WINS], [Result.TOP_WINS, Result.BOTTOM_WINS, Result.BOTTOM_WINS], [Result.TOP_WINS, Result.BOTTOM_WINS, Result.TOP_WINS], [Result.TOP_WINS, Result.TOP_WINS, Result.BOTTOM_WINS], [Result.TOP_WINS, Result.TOP_WINS, Result.TOP_WINS] ] for bracket, results in zip(all_brackets, all_results): actual_matches = bracket.matches semifinal_0 = hedger.Match( round_=0, index=0, top=gryffindor, bottom=ravenclaw, result=results[0] ) semifinal_1 = hedger.Match( round_=0, index=1, top=hufflepuff, bottom=slytherin, result=results[1] ) final = hedger.Match( round_=1, index=0, top=semifinal_0, bottom=semifinal_1, result=results[2] ) expected_matches = [semifinal_0, semifinal_1, final] self.assertEqual(actual_matches, expected_matches)
def test_winner_of_match_with_invalid_result_is_none(self): match_with_invalid_result = hedger.Match( round_=0, index=0, top=self.entry_a, bottom=self.entry_b, result="not a valid result" ) self.assertIsNone(match_with_invalid_result.winner)
def test_match_with_two_submatches(self): submatch_0 = hedger.Match( round_=0, index=0, top=self.entry_a, bottom=self.entry_b, result=Result.TOP_WINS ) submatch_1 = hedger.Match( round_=0, index=1, top=self.entry_c, bottom=self.entry_d, result=Result.BOTTOM_WINS ) match = hedger.Match( round_=1, index=0, top=submatch_0, bottom=submatch_1, result=Result.BOTTOM_WINS ) top_str = ( "Match(round_=0, index=0, top=Entry('A'), " "bottom=Entry('B'), result=Result.TOP_WINS)" ) bottom_str = ( "Match(round_=0, index=1, top=Entry('C'), " "bottom=Entry('D'), result=Result.BOTTOM_WINS)" ) expected_fmt = ( "Match(round_=1, index=0, top={top}, " "bottom={bottom}, result=Result.BOTTOM_WINS)" ) expected = expected_fmt.format(top=top_str, bottom=bottom_str) self.assertEqual(repr(match), expected) self.assertEqual(match.winner, self.entry_d)
def setUp(self): self.entry_a = hedger.Entry('A') self.entry_b = hedger.Entry('B') self.entry_c = hedger.Entry('C') self.entry_d = hedger.Entry('D') self.match = hedger.Match( round_=0, index=0, top=self.entry_a, bottom=self.entry_b, result=Result.TOP_WINS )
def test_get_result_probabilities_using_example_from_538_csv(self): virginia = hedger.Entry('Virginia', 88.07) ohio = hedger.Entry('Ohio', 77.51) match = hedger.Match( round_=0, index=4, top=virginia, bottom=ohio, result=Result.BOTTOM_WINS ) expected = .136 actual = match.get_prob() self.assertAlmostEqual(actual, expected, 3)
def test_get_result_probabilities_of_equally_rated_teams(self): entry_1 = hedger.Entry('Team 1', 100) entry_2 = hedger.Entry('Team 2', 100) match = hedger.Match( round_=0, index=0, top=entry_1, bottom=entry_2, result=Result.TOP_WINS ) expected = .5 actual = match.get_prob() self.assertEqual(actual, expected)
def _make_this_round_matches(self): index = 0 this_round_matches = list() for top, bottom in utils.pairwise_grouper( self._last_round_matches, fillvalue=hedger.EmptyEntry()): new_match = hedger.Match(round_=self._round, index=index, top=top, bottom=bottom, result=next(self._result_iter)) this_round_matches.append(new_match) index += 1 return this_round_matches
def test_match_with_two_entries(self): match = hedger.Match( round_=0, index=0, top=self.entry_a, bottom=self.entry_b, result=Result.TOP_WINS ) expected = ( "Match(round_=0, index=0, top=Entry('A'), " "bottom=Entry('B'), result=Result.TOP_WINS)" ) self.assertEqual(repr(match), expected) self.assertEqual(match.winner, self.entry_a)