Example #1
0
    def test_report_result_when_all_games_played(self):
        bot1, bot2 = [factories.create_bot() for _ in range(2)]

        for _ in range(5):
            factories.report_result(bot1.id, bot2.id, 0)

        actions.report_result(bot1.id, bot2.id, self.build_result(1))

        self.assertEqual(models.Game.objects.count(), 5)
Example #2
0
def report_result(bot1_id, bot2_id, score, move_list=None):
    if move_list is None:
        move_list = []

    result = Result(
        result_type=ResultType.COMPLETE,
        score=score,
        move_list=move_list,
        traceback=None,
        invalid_move=None,
    )

    actions.report_result(bot1_id, bot2_id, result)
Example #3
0
    def test_report_result_for_incomplete_game(self):
        bot1, bot2 = [factories.create_bot() for _ in range(2)]

        result = self.build_result(1, ResultType.EXCEPTION)
        actions.report_result(bot1.id, bot2.id, result)

        game = models.Game.objects.get()

        self.assertEqual(game.bot1_id, bot1.id)
        self.assertEqual(game.bot2_id, bot2.id)
        self.assertEqual(game.score, 1)
        self.assertEqual(game.moves, "01478")
        self.assertEqual(game.result_type, "exception")
        self.assertEqual(game.traceback, "KeyError ...")
Example #4
0
    def test_report_result(self):
        bot1, bot2 = [factories.create_bot() for _ in range(2)]

        actions.report_result(bot1.id, bot2.id, self.build_result(1))

        game = models.Game.objects.get()

        self.assertEqual(game.bot1_id, bot1.id)
        self.assertEqual(game.bot2_id, bot2.id)
        self.assertEqual(game.score, 1)
        self.assertEqual(game.moves, "01478")
        self.assertEqual(game.result_type, "complete")

        actions.report_result(bot1.id, bot2.id, self.build_result(-1))
        actions.report_result(bot2.id, bot1.id, self.build_result(1))
        actions.report_result(bot2.id, bot1.id, self.build_result(0))

        self.assertEqual(bot1.bot1_games.count(), 2)
        self.assertEqual(bot1.bot2_games.count(), 2)

        self.assertEqual(bot1.score, -1)
        self.assertEqual(bot2.score, 1)