Пример #1
0
    def create_new_double_elimination(self, request, queryset):
        teams = list(queryset)
        if len(teams) < 1:
            from django.contrib import messages
            messages.error(request, _('no selected teams!'))
            return

        first_challenge = teams[0].challenge
        for team in teams:
            if team.challenge != first_challenge:
                from django.contrib import messages
                messages.error(request, _('Only teams from one challenge!'))
                return
        new_competition = Competition(challenge=first_challenge, name=str(len(first_challenge.competitions.all()) + 1),
                                      type='double')
        new_competition.save()
        new_competition.create_new_double_elimination(
            [team.team for team in teams]
        )
        new_competition.save()
Пример #2
0
    def test_create_new_double_elimination(self):
        challenge = Challenge.objects.all()[0]
        for team in Team.objects.all():
            participation = TeamParticipatesChallenge()
            participation.team = team
            participation.challenge = challenge
            participation.save()

        competition = Competition(challenge=challenge, type='double')
        competition.save()

        maps = list(Map.objects.all())
        for map in maps:
            competition.maps.add(map)

        competition.create_new_double_elimination(teams=Team.objects.all())

        # expected result
        # 1 -> 2
        # 3 -> 4
        # 1 -> 2
        # 1 -> 2
        # 4 -> 3
        # 5 -> 3
        # 5 -> 3
        #
        matches = list(Match.objects.all())
        self.assertEqual(matches[0].part1.object_id, 1)
        self.assertEqual(matches[0].part2.object_id, 2)
        self.assertEqual(matches[1].part1.object_id, 3)
        self.assertEqual(matches[1].part2.object_id, None)
        self.assertEqual(matches[2].part1.object_id, 1)
        self.assertEqual(matches[2].part2.object_id, 2)
        self.assertEqual(matches[3].part1.object_id, 1)
        self.assertEqual(matches[3].part2.object_id, 2)
        self.assertEqual(matches[4].part1.object_id, 4)
        self.assertEqual(matches[4].part2.object_id, 3)
        self.assertEqual(matches[5].part1.object_id, 3)
        self.assertEqual(matches[5].part2.object_id, 5)
        self.assertEqual(matches[6].part1.object_id, 3)
        self.assertEqual(matches[6].part2.object_id, 5)