def test_loads_history_invalid_json(self): fun = funes.funes() self.assertEqual([], fun.get_history()) # still usable minqlx_fake.run_game(PLAYER_ID_MAP, [15, 12], [13, 16], 7, 15) teams = ((34, 12), (56, 78)) self.assertEqual([0, 0], fun.get_teams_history('ad', teams)) self.assertEqual([0, 0], fun.get_teams_history('ad', teams, aggregate=True))
def test_saves_history_same_date(self, m): fun = funes.funes() self.assertEqual(HISTORY_DATA, fun.get_history()) red_ids = [15, 12] blue_ids = [13, 16] minqlx_fake.run_game(PLAYER_ID_MAP, red_ids, blue_ids, 15, 14) expected = copy.deepcopy(HISTORY_DATA) expected.append(['2018-10', 'ad', [12, 15], [13, 16], 15, 14]) self.assertSavedJson(expected, m)
def test_saves_stats(self, m): olor = oloraculo.oloraculo() # red_team_ids, blue_team_ids, red_score, blue_score minqlx_fake.run_game(PLAYER_ID_MAP, [56, 78], [12, 34], 7, 15) expected_data = { 'ad': { '12': [2, 0, 3, 1, 200, 100], '34': [3, 0, 2, 4, 100, 900], '56': [2, 0, 3, 3, 300, 200], '78': [3, 0, 1, 9, 100, 900], }, } self.assertSavedJson(expected_data, m)
def test_handles_game_end(self): olor = oloraculo.oloraculo() # red_team_ids, blue_team_ids, red_score, blue_score minqlx_fake.run_game(PLAYER_ID_MAP, [56, 78], [12, 34], 7, 15) stats = olor.get_stats() # winloss self.assertEqual([3, 1], stats.get_winloss('ad', 12)) self.assertEqual([2, 4], stats.get_winloss('ad', 34)) self.assertEqual([3, 3], stats.get_winloss('ad', 56)) self.assertEqual([1, 9], stats.get_winloss('ad', 78)) # ratings self.assertEqual(trueskill_fake.Rating(2), stats.get_rating('ad', 12)) self.assertEqual(trueskill_fake.Rating(3), stats.get_rating('ad', 34)) self.assertEqual(trueskill_fake.Rating(2), stats.get_rating('ad', 56)) self.assertEqual(trueskill_fake.Rating(3), stats.get_rating('ad', 78))
def test_handles_game_end(self, m): fun = funes.funes() red_ids = [10, 11, 12] blue_ids = [15, 13, 14] teams = (red_ids, blue_ids) self.assertEqual([1, 0], fun.get_teams_history('ad', teams)) self.assertEqual([5, 2], fun.get_teams_history('ad', teams, aggregate=True)) # blue won minqlx_fake.run_game(PLAYER_ID_MAP, red_ids, blue_ids, 7, 15) self.assertEqual([1, 1], fun.get_teams_history('ad', teams)) self.assertEqual([5, 3], fun.get_teams_history('ad', teams, aggregate=True)) # red won minqlx_fake.run_game(PLAYER_ID_MAP, red_ids, blue_ids, 15, 1) self.assertEqual([2, 1], fun.get_teams_history('ad', teams)) self.assertEqual([6, 3], fun.get_teams_history('ad', teams, aggregate=True))
def test_handles_game_end_no_update(self): fun = funes.funes() red_ids = [10, 15, 12] blue_ids = [11, 14, 13] teams = (red_ids, blue_ids) self.assertEqual([2, 1], fun.get_teams_history('ad', teams)) self.assertEqual([3, 1], fun.get_teams_history('ad', teams, aggregate=True)) # aborted minqlx_fake.run_game(PLAYER_ID_MAP, red_ids, blue_ids, 7, 15, True) self.assertEqual([2, 1], fun.get_teams_history('ad', teams)) self.assertEqual([3, 1], fun.get_teams_history('ad', teams, aggregate=True)) # no team won minqlx_fake.run_game(PLAYER_ID_MAP, red_ids, blue_ids, 7, 10) self.assertEqual([2, 1], fun.get_teams_history('ad', teams)) self.assertEqual([3, 1], fun.get_teams_history('ad', teams, aggregate=True)) # empty team minqlx_fake.run_game(PLAYER_ID_MAP, [], blue_ids, 7, 15) self.assertEqual([2, 1], fun.get_teams_history('ad', teams)) self.assertEqual([3, 1], fun.get_teams_history('ad', teams, aggregate=True))
def test_handles_game_end_no_update(self): olor = oloraculo.oloraculo() original_stats = olor.get_stats() # aborted minqlx_fake.run_game(PLAYER_ID_MAP, [56, 78], [12, 34], 7, 15, True) self.assertEqual(original_stats, olor.get_stats()) # final score is < required (15) minqlx_fake.run_game(PLAYER_ID_MAP, [56, 78], [12, 34], 7, 14) self.assertEqual(original_stats, olor.get_stats()) # all valid minqlx_fake.run_game(PLAYER_ID_MAP, [56, 78], [12, 34], 7, 16) self.assertNotEqual(original_stats, olor.get_stats())