예제 #1
0
def test_split_players():

    groups = split_players_to_groups(['a'] * 10)
    assert groups == [['a'] * 5] * 2

    groups = split_players_to_groups(['a'] * 6)
    assert groups == [['a'] * 6]

    groups = split_players_to_groups(['a'] * 16)
    assert groups == [['a'] * 4] * 4

    groups = split_players_to_groups(['a'] * 17)
    assert groups == [['a'] * 5] + [['a'] * 4] * 3
예제 #2
0
파일: models.py 프로젝트: oeegor/pong
    def create_groups(self):
        if self.groups.all().exists():
            raise RuntimeError("groups are already created for this stage")

        stage_participants = list(self.participants.all().order_by("?"))
        if len(stage_participants) == 0:
            raise RuntimeError("cannot create groups for empty stage")

        groups = split_players_to_groups(stage_participants)
        for idx, group in enumerate(groups):
            dj_group = Group.objects.create(stage=self, name=chr(97 + idx).upper())
            dj_group.participants.add(*group)