Пример #1
0
def make_teams(teamscores):
    quiz = Quiz()
    for i, teamscore in enumerate(teamscores, start=1):
        quiz.get_team(i, 'team {}'.format(i))

    for section_nr in range(len(teamscores[0])):
        section = Section(name='section {}'.format(section_nr), quiz=quiz)
        section.scores = lambda i=section_nr: {quiz.teams[j]: t[i] for j, t in enumerate(teamscores)}

    return quiz
Пример #2
0
    def test_when_teams_in_same_section_expect_cannot_be_merged(self):
        # ARRANGE
        quiz = Quiz()
        section = Section(quiz=quiz)
        team1 = quiz.get_team(1, 'test_1')
        section.add_response(Response(team=team1))

        team2 = quiz.get_team(2, 'test_2')
        section.add_response(Response(team=team2))

        # ACT
        result = quiz.can_merge_teams([team1, team2])

        # ASSERT
        self.assertFalse(result)
Пример #3
0
    def test_when_merging_teams_and_both_in_section_expect_failure(self):
        # ARRANGE
        quiz = Quiz()
        section = Section(quiz=quiz)
        team1 = quiz.get_team(1, 'test_1')
        section.add_response(Response(team=team1))
        team2 = quiz.get_team(2, 'test_2')
        section.add_response(Response(team=team2))

        # ACT
        with self.assertRaises(Exception):
            quiz.merge_teams([team1, team2])

        # ASSERT
        pass
Пример #4
0
    def test_when_sections_of_teams_dont_overlap_expect_can_be_merged(self):
        # ARRANGE
        quiz = Quiz()
        section1 = Section(quiz=quiz)
        team1 = quiz.get_team(1, 'test_1')
        section1.add_response(Response(team=team1))

        section2 = Section(quiz=quiz)
        team2 = quiz.get_team(2, 'test_2')
        section2.add_response(Response(team=team2))

        # ACT
        result = quiz.can_merge_teams([team1, team2])

        # ASSERT
        self.assertTrue(result)
Пример #5
0
    def test_when_only_one_team_expect_cannot_be_merged(self):
        # ARRANGE
        quiz = Quiz()
        team = quiz.get_team(1, 'team 1')

        # ACT
        result = quiz.can_merge_teams([team])

        # ASSERT
        self.assertFalse(result)
Пример #6
0
    def test_get_existing_team_with_quiz(self):
        quiz = Quiz()
        team = Team('12', 'test team')
        quiz.teams = [team]

        # ACT
        result = quiz.get_team('12', 'testing team')

        # ASSERT
        self.assertEqual(result, team)
        self.assertEqual(len(quiz.teams), 1)
Пример #7
0
    def test_create_new_team_with_quiz(self):
        quiz = Quiz()

        # ACT
        result = quiz.get_team('12', 'test team')

        # ASSERT
        self.assertIsInstance(result, Team)
        self.assertEqual(result.team_id, '12')
        self.assertEqual(result.name, 'test team')

        self.assertEqual(len(quiz.teams), 1)
Пример #8
0
    def test_when_merging_teams_expect_scores_are_added(self):
        # ARRANGE
        quiz = Quiz()
        section1 = Section(quiz=quiz)
        team1 = quiz.get_team(1, 'test_1')
        response1 = Response(team=team1)
        response1.score = lambda: 4
        section1.add_response(response1)

        section2 = Section(quiz=quiz)
        team2 = quiz.get_team(2, 'test_2')
        response2 = Response(team=team2)
        response2.score = lambda: 5
        section2.add_response(response2)

        # ACT
        quiz.merge_teams([team1, team2])

        # ASSERT
        self.assertEqual(section2.scores(), {team1: 5})
        self.assertEqual(quiz.scores(), {team1: 9})
Пример #9
0
    def test_when_merging_teams_expect_only_one_team_remains(self):
        # ARRANGE
        quiz = Quiz()
        team1 = quiz.get_team(1, 'test_1')
        team2 = quiz.get_team(2, 'test_2')

        # ACT
        quiz.merge_teams([team1, team2])

        # ASSERT
        self.assertIn(team1, quiz.teams)
        self.assertNotIn(team2, quiz.teams)
Пример #10
0
    def test_when_merging_teams_expect_team_in_section_changes(self):
        # ARRANGE
        quiz = Quiz()
        section = Section(quiz=quiz)
        team1 = quiz.get_team(1, 'test_1')
        team2 = quiz.get_team(2, 'test_2')
        section.add_response(Response(team=team2))

        # ACT
        quiz.merge_teams([team1, team2])

        # ASSERT
        self.assertEqual(len(section.responses), 1)
        self.assertEqual(section.responses[0].team, team1)