Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    def test_update_exp_blue_wins(self):
        match = Match(red_score=10, blue_score=8, **self.members_0)
        exp_0 = (self.members_0['red_att'].exp, self.members_0['red_def'].exp,
                 self.members_0['blue_att'].exp,
                 self.members_0['blue_def'].exp)
        match.save()
        points = match.points
        exp_1 = (self.members_0['red_att'].exp, self.members_0['red_def'].exp,
                 self.members_0['blue_att'].exp,
                 self.members_0['blue_def'].exp)

        self.assertEqual(exp_0[0] + points, exp_1[0])
        self.assertEqual(exp_0[1] + points, exp_1[1])
        self.assertEqual(exp_0[2] - points, exp_1[2])
        self.assertEqual(exp_0[3] - points, exp_1[3])
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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})
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 def test_below_0(self):
     match = Match(red_score=10, blue_score=-5, **self.members_0)
     with self.assertRaises(AssertionError):
         match.save()
Ejemplo n.º 8
0
 def create_history(self):
     for match in Match.objects.all().order_by('date'):
         self.update_members_exp(match)
         Match.create_exp_history(match)