def test_bias(self): for score in range(1, 11): match = Match(red_score=10, blue_score=score, **self.members_0) points_0, _ = match.calculate_points() match_1 = Match(red_score=score, blue_score=10, **self.members_1) points_1, _ = match_1.calculate_points() self.assertEqual(points_0, -points_1)
def points(self, request, *args, **kwargs): data = {k + '_id': v for k, v in request.query_params.items()} match = Match(**data, red_score=0, blue_score=10) try: result1 = abs(match.calculate_points()[0]) except (Match.red_att.RelatedObjectDoesNotExist, Match.red_def.RelatedObjectDoesNotExist, Match.blue_att.RelatedObjectDoesNotExist, Match.blue_def.RelatedObjectDoesNotExist): return Response({'detail': 'Players have not been provided'}, status=406) match = Match(**data, red_score=10, blue_score=0) result2 = abs(match.calculate_points()[0]) return Response({'blue': result1, 'red': result2})
def test_unequal_tie(self): self.assertNotEqual( self.members_0['red_att'].exp + self.members_0['red_def'].exp, self.members_0['blue_att'].exp + self.members_0['blue_def'].exp) for score in range(1, 11): match = Match(red_score=score, blue_score=score, **self.members_0) _, winner = match.calculate_points() self.assertEqual(winner, Match.TIE)
def test_0_10(self): match = Match(red_score=0, blue_score=10, **self.members_0) points, winner = match.calculate_points() self.assertLessEqual(points, 0) self.assertEqual(winner, Match.BLUE)
def test_10_0(self): match = Match(red_score=10, blue_score=0, **self.members_0) points, winner = match.calculate_points() self.assertGreaterEqual(points, 0) self.assertEqual(winner, Match.RED)