def test_process_game_tie(self): record = Record(-1, "Me", -1, 0, 0, 0, 0, 0, 0, "") record.process_game(2, 2) self.assertEqual(0, record.wins) self.assertEqual(0, record.loses) self.assertEqual(1, record.ties) self.assertEqual(2, record.goals_for) self.assertEqual(2, record.goals_against)
def test_sort_records_default(self): r1 = Record(-1, Team("Team 1", 5, False), 255, 10, 0, 0, 0, 0, 0, "") r2 = Record(-1, Team("Team 2", 5, False), 255, 9, 0, 2, 0, 0, 0, "") r3 = Record(-1, Team("Team 3", 5, False), 255, 6, 2, 2, 0, 0, 0, "") r4 = Record(-1, Team("Team 4", 5, False), 255, 7, 3, 0, 0, 0, 0, "") r5 = Record(-1, Team("Team 5", 5, False), 255, 0, 0, 4, 12, 12, 0, "") r6 = Record(-1, Team("Team 6", 5, False), 255, 0, 0, 4, 6, 12, 0, "") r7 = Record(-1, Team("Team 7", 5, False), 255, 0, 0, 4, 12, 6, 0, "") records = [r7, r5, r6, r1, r2, r4, r3] Record.sort_records_default(records) self.assertEqual(1, records[0].rank) self.assertEqual(2, records[1].rank) self.assertEqual(3, records[2].rank) self.assertEqual(4, records[3].rank) self.assertEqual(5, records[4].rank) self.assertEqual(6, records[5].rank) self.assertEqual(7, records[6].rank) self.assertEqual("Team 1", records[0].team.name) self.assertEqual("Team 2", records[1].team.name) self.assertEqual("Team 4", records[2].team.name) self.assertEqual("Team 3", records[3].team.name) self.assertEqual("Team 7", records[4].team.name) self.assertEqual("Team 5", records[5].team.name) self.assertEqual("Team 6", records[6].team.name)
def test_stats(self): t1_skill = 10 t2_skill = 0 team1 = Team("T1", t1_skill, True, "1") team2 = Team("T2", t2_skill, True, "2") record1 = Record(1, team1, 1, 0, 0, 0, 0, 0, 0, "3") record2 = Record(1, team2, 1, 0, 0, 0, 0, 0, 0, "3") rules = GameRules("Rules", True, "4") for i in range(1000): game = Game(1, 1, team1, team2, 0, 0, False, False, rules, str(i)) game.play() record1.process_game(game.home_score, game.away_score) record2.process_game(game.away_score, game.home_score) print() print("Results") print(RecordView.get_table_header()) print( RecordView.get_table_row( RecordService.get_view_from_model(record1))) print( RecordView.get_table_row( RecordService.get_view_from_model(record2)))
def add(self, team_view_list, year, session=None): commit = session is None session = self.get_session(session) team_list = [self.get_team_repo().get_by_oid(t.oid, session) for t in team_view_list] record_list = [Record(-1, t, year, 0, 0, 0, 0, 0, t.skill, self.get_new_id()) for t in team_list] [self.get_repo().add(r, session) for r in record_list] self.commit(session, commit)
def __init__(self, sub_competition, rank, team, year, wins, loses, ties, goals_for, goals_against, skill, oid=None): self.sub_competition = sub_competition Record.__init__(self, rank, team, year, wins, loses, ties, goals_for, goals_against, skill, oid)
def test_add_new_team(self): session = self.setup_basic_test() team_id = IDHelper.get_new_id() team = Team("Record Add For New Team", 5, True, team_id) record = Record(1, team, 1, 2, 3, 4, 5, 6, 7, IDHelper.get_new_id()) self.get_repo().add(record, session) session.commit() result = self.get_repo().get_by_oid(record.oid, session) self.assertEqual(result.oid, record.oid) self.assertEqual(result.team.oid, record.team.oid)
def test_get_points(self): record = Record(-1, None, -1, 0, 0, 0, 0, 0, 0, "") self.assertEqual(0, record.points) record.goals_for = 5 self.assertEqual(0, record.points) record.goals_against = 3 self.assertEqual(0, record.points) record.wins = 12 self.assertEqual(24, record.points) record.loses = 3 self.assertEqual(24, record.points) record.ties = 22 self.assertEqual(46, record.points)
def test_get_all(self): session = self.setup_basic_test() team_names = ["Team A1", "Team A2", "Team A5"] [ self.get_team_repo().add(Team(t, 0, True, IDHelper.get_new_id()), session) for t in team_names ] session.commit() [ self.get_repo().add( Record(1, team, 1, 2, 3, 4, 5, 6, 7, IDHelper.get_new_id()), session) for team in self.get_team_repo().get_all(session) ] session.commit() self.assertEqual(3, len(self.get_repo().get_all(session)))
def test_get_goal_difference(self): record = Record(-1, None, -1, 1, 2, 3, 4, 10, 0, "") self.assertEqual(-6, record.goal_difference)
def test_get_games(self): record = Record(-1, None, -1, 1, 2, 3, 0, 0, 0, "") self.assertEqual(6, record.games)
def get_add_record(self): return RecordDTO( Record(5, TeamDTO(Team("Team Name", 5, True)), 25, 10, 20, 30, 40, 50, 200))
def setup_record_query_data(self, session): team_list = [] for i in range(10): new_id = IDHelper.get_new_id() team_list.append(Team("GBYN " + str(i), i, True, new_id)) [self.get_team_repo().add(t, session) for t in team_list] # need them to be DTOs! team_list = self.get_team_repo().get_all(session) record_year_30 = [ self.get_repo().add( Record(1, team_list[0], 30, 0, 0, 0, 0, 0, 0, self.get_id()), session), self.get_repo().add( Record(2, team_list[1], 30, 0, 0, 0, 0, 0, 0, self.get_id()), session), self.get_repo().add( Record(3, team_list[2], 30, 0, 0, 0, 0, 0, 0, self.get_id()), session), ] record_year_31 = [ self.get_repo().add( Record(1, team_list[2], 31, 0, 0, 0, 0, 0, 0, self.get_id()), session), self.get_repo().add( Record(1, team_list[4], 31, 0, 0, 0, 0, 0, 0, self.get_id()), session), self.get_repo().add( Record(1, team_list[6], 31, 0, 0, 0, 0, 0, 0, self.get_id()), session), self.get_repo().add( Record(1, team_list[8], 31, 0, 0, 0, 0, 0, 0, self.get_id()), session), self.get_repo().add( Record(1, team_list[9], 31, 0, 0, 0, 0, 0, 0, self.get_id()), session), ] record_year_32 = [ self.get_repo().add( Record(1, team_list[5], 32, 0, 0, 0, 0, 0, 0, self.get_id()), session), self.get_repo().add( Record(1, team_list[3], 32, 0, 0, 0, 0, 0, 0, self.get_id()), session), ] record_year_33 = [ self.get_repo().add( Record(1, team_list[1], 33, 0, 0, 0, 0, 0, 0, self.get_id()), session), ] session.commit()
def __init__(self, record): team_dto = TeamDTO.get_dto(record.team) Record.__init__(self, record.rank, team_dto, record.year, record.wins, record.loses, record.ties, record.goals_for, record.goals_against, record.skill, record.oid)