def test_find(self): players = [ Player(name="Daniel Baraldi Marcos"), Player(name="Dekel Bar"), ] self.assertEqual( AbbrName("Bar D.").find_player(players), Player(name="Dekel Bar")) players = [ Player(name="Daniel Baraldi Marcos"), Player(name="Dekel Bar"), Player(name="Dekel Bar Foo"), ] self.assertEqual( AbbrName("Bar D.").find_player(players), Player(name="Dekel Bar")) players = [Player(name="Dekel Bar Foo")] self.assertEqual(AbbrName("Bar D.").find_player(players), players[0]) players = [Player(name="Nils Brinkman")] self.assertEqual( AbbrName("Brinkman N.").find_player(players), players[0]) players = [Player(name="Michelle Larcher De Brito")] self.assertEqual( AbbrName("Larcher de Brito M.").find_player(players), players[0])
def play_game(TennisGame, p1Points, p2Points, p1Name, p2Name): player_one = Player(p1Name) player_two = Player(p2Name) game = TennisGame(player_one, player_two) for i in range(max(p1Points, p2Points)): if i < p1Points: game.player_one.point_won() if i < p2Points: game.player_two.point_won() return game
def test_get_rank_atp(self): date = datetime.date(2014, 7, 21) plr = Player(ident=21812, name="Rodrigo Arus", cou="URU") pos = get_rank("atp", plr.ident, date) self.assertEqual(pos, None) plr = Player(ident=13962, name="Valentin Florez", cou="ARG") pos = get_rank("atp", plr.ident, date) self.assertEqual(pos, 689)
def test_recent_winner(self): plr1 = Player(ident=6590, name="Cagla Buyukakcay", cou="TUR") plr2 = Player(ident=8951, name="Veronica Cepede Royg", cou="PAR") match = Match(first_player=plr1, second_player=plr2, score=None, rnd=Round('Second'), date=datetime.date(2019, 10, 18)) h2h = HeadToHead(sex='wta', match=match, completed_only=True) recent_winner_id = h2h.recently_won_player_id() self.assertEqual(recent_winner_id, plr1.ident)
def test_ito_kukushkin(self): plr1 = Player(ident=8313, name="Tatsuma Ito", cou="JPN") plr2 = Player(ident=9043, name="Mikhail Kukushkin", cou="KAZ") match = Match( first_player=plr1, second_player=plr2, score=sc.Score("4-6 7-6(3) 7-6(6)"), rnd=Round("Second"), date=datetime.date(2017, 2, 1), ) h2hdir = HeadToHead(sex="atp", match=match, completed_only=True).direct() self.assertEqual(h2hdir, None)
def player_load(prefix: str, player: tennis.Player): player.ident = dct.get(prefix + "_player_id") player.name = dct.get(prefix + "_player_name") player.rating = ratings.Rating(dct.get(prefix + "_player_rating")) ymd = dct.get(prefix + "_player_bdate") if ymd is not None: player.birth_date = datetime.date(ymd[0], ymd[1], ymd[2]) setattr( self, "hist_" + prefix + "_srv_win", rl.SizedValue(*dct[prefix + "_hist_srv_win"]), ) setattr( self, "hist_" + prefix + "_rcv_win", rl.SizedValue(*dct[prefix + "_hist_rcv_win"]), )
def test_get_puig_sharapova(self): plr1 = Player(ident=10222, name="Monica Puig", cou="PUR") plr2 = Player(ident=503, name="Maria Sharapova", cou="RUS") mstat = get( sex="wta", tour_id=9125, rnd=Round("Second"), first_player_id=plr1.ident, second_player_id=plr2.ident, year_weeknum=tt.get_year_weeknum(datetime.date(2014, 5, 14)), ) self.assertNotEqual(mstat, None) self.assertEqual(mstat.left_side.aces, 3) self.assertEqual(mstat.right_side.aces, 5) self.assertEqual(mstat.left_side.first_service_in, WinLoss(32, 24)) self.assertEqual(mstat.right_side.first_service_in, WinLoss(38, 25)) self.assertEqual(mstat.left_side.bp_win, WinLoss(2, 5)) self.assertEqual(mstat.right_side.bp_win, WinLoss(4, 3)) self.assertEqual(mstat.total_points_won(), (51, 68))
def test_get_rank_wta(self): plr = Player(ident=14364, name="Angeliki Kairi", cou="GRE") pos = get_rank("wta", plr.ident, datetime.date(2014, 7, 21)) self.assertEqual(pos, None) plr = Player(ident=14010, name="Beatrice Cedermark", cou="SWE") pos = get_rank("wta", plr.ident, datetime.date(2014, 7, 21)) self.assertEqual(pos, 723) plr = Player(ident=431, name="Vera Zvonareva", cou="RUS") pos = get_rank("wta", plr.ident, datetime.date(2012, 5, 28)) self.assertEqual(pos, 11) pts = get_pts("wta", plr.ident, datetime.date(2012, 5, 28)) self.assertEqual(pts, 344000) pos = get_rank("wta", plr.ident, datetime.date(2003, 1, 13)) self.assertEqual(pos, 43) plr = Player(ident=7574, name="Petra Martic", cou="CRO") pos = get_rank("wta", plr.ident, datetime.date(2020, 8, 3)) self.assertEqual(pos, 15)
def __init__( self, date, sex: str, tour_name: TourName, level: Level, rnd: Round, fst_name: str, snd_name: str, std_score: Score, href: str, best_of_five=None, ): self.date = date self.sex = sex self.tour_name = tour_name self.first_player = Player(ident=None, name=fst_name) self.second_player = Player(ident=None, name=snd_name) self.level = level self.rnd = rnd self.score = std_score self.href = href self.best_of_five = best_of_five
def test_get_baroni_williams(self): """baroni win 6-4 6-3""" plr1 = Player(ident=180, name="Mirjana Lucic-Baroni", cou="CRO") plr2 = Player(ident=151, name="Venus Williams", cou="USA") mstat = get( sex="wta", tour_id=9148, rnd=Round("Final"), first_player_id=plr1.ident, second_player_id=plr2.ident, year_weeknum=tt.get_year_weeknum(datetime.date(2014, 9, 14)), ) self.assertNotEqual(mstat, None) self.assertEqual(mstat.left_side.aces, 6) self.assertEqual(mstat.right_side.aces, 5) self.assertEqual(mstat.left_side.bp_win, WinLoss(4, 7)) self.assertEqual(mstat.right_side.bp_win, WinLoss(2, 2)) self.assertEqual(mstat.left_side.first_service_win, WinLoss(31, 9)) self.assertEqual(mstat.right_side.first_service_win, WinLoss(23, 14)) self.assertEqual(mstat.left_side.second_service_win, WinLoss(10, 13)) self.assertEqual(mstat.right_side.second_service_win, WinLoss(11, 21)) self.assertEqual(mstat.left_side.double_faults, 4) self.assertEqual(mstat.right_side.double_faults, 2) self.assertEqual(mstat.total_points_won(), (76, 56))