def test_when_team_has_one_response_expect_one_response(self): # ARRANGE section = Section() team = section.get_team('1', 'team 1') response = Response(team=team) section.add_response(response) # ACT result = section.response_for_team(team) # ASSERT self.assertEqual(result, response)
def test_when_team_has_multiple_responses_expect_all_responses(self): # ARRANGE section = Section() team = section.get_team('1', 'team 1') response1 = Response(team=team) section.add_response(response1) response2 = Response(team=team) section.add_response(response2) # ACT result = section.responses_for_team(team) # ASSERT self.assertEqual(result, {response1, response2})
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)
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)
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
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)
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})
def test_when_team_has_multiple_responses_expect_first(self): # ARRANGE section = Section() team = section.get_team('1', 'team 1') response1 = Response(team=team, timestamp='2020/11/01 20:00:00') section.add_response(response1) response2 = Response(team=team, timestamp='2020/11/01 19:00:00') section.add_response(response2) response3 = Response(team=team, timestamp='2020/11/01 21:00:00') section.add_response(response3) # ACT result = section.response_for_team(team) # ASSERT self.assertEqual(result, response2)
def test_when_team_has_multiple_responses_expect_only_score_of_first_response( self): section = Section() team = section.get_team('1', 'team1') response1 = Response(team=team, timestamp='2020/11/01 20:00:00') response1.score = lambda: 5 section.add_response(response1) response2 = Response(team=team, timestamp='2020/11/01 19:00:00') response2.score = lambda: 4 section.add_response(response2) response3 = Response(team=team, timestamp='2020/11/01 21:00:00') response3.score = lambda: 3 section.add_response(response3) # ACT result = section.scores() # ASSERT self.assertEqual(result, {team: 4})