Ejemplo n.º 1
0
 def test_game_does_not_load_questions_in_the_questions_asked_list_to_rounds(
         self):
     initial_questions = [{
         'Round': 1,
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }, {
         'Round': 2,
         'Ask': 'What is your name?',
         'Answer': 'Sir Lancelot of Camelot'
     }, {
         'Round': 2,
         'Ask': 'What is your quest?',
         'Answer': 'To seek the Holy Grail'
     }, {
         'Round': 2,
         'Ask': 'What is your favorite color?',
         'Answer': 'Blue'
     }, {
         'Round': 3,
         'Ask': 'Are you a god?',
         'Answer': 'YES!'
     }]
     mock_questions_asked = Questions_Asked()
     mock_questions_asked._log = [{
         'Round':
         1,
         'Ask':
         "What's a Diorama?",
         'Answer':
         "OMG Han! Chewie! They're all here!"
     }, {
         'Round': 2,
         'Ask': 'What is your name?',
         'Answer': 'Sir Lancelot of Camelot'
     }]
     expected_questions = [
         [{
             'Round': 2,
             'Ask': 'What is your quest?',
             'Answer': 'To seek the Holy Grail'
         }, {
             'Round': 2,
             'Ask': 'What is your favorite color?',
             'Answer': 'Blue'
         }],
         [{
             'Round': 3,
             'Ask': 'Are you a god?',
             'Answer': 'YES!'
         }],
     ]
     s = Subject(Connection(), initial_questions, mock_questions_asked,
                 Player_Scores(), Timer())
     actual_questions = s.list_by_rounds(initial_questions)
     self.assertEqual(actual_questions, expected_questions)
Ejemplo n.º 2
0
    def test_round_lets_the_chat_know_when_the_round_is_over_by_listing_round_winners(
            self):
        questions = [
            {
                'Round': 2,
                'Ask': 'What is your name?',
                'Answer': 'Sir Lancelot of Camelot'
            },
            {
                'Round': 2,
                'Ask': 'What is your quest?',
                'Answer': 'To seek the Holy Grail'
            },
            {
                'Round': 2,
                'Ask': 'What is your favorite color?',
                'Answer': 'Blue'
            },
        ]
        mock_connection = Connection()
        mock_player_scores = Player_Scores()
        gold = f"{mock_player_scores._round_winners[0][0]}: {mock_player_scores._round_winners[0][1]}"
        silver = f"{mock_player_scores._round_winners[1][0]}: {mock_player_scores._round_winners[1][1]}"
        bronze = f"{mock_player_scores._round_winners[2][0]}: {mock_player_scores._round_winners[2][1]}"

        s = Subject(mock_connection, questions, Questions_Asked(),
                    mock_player_scores, Timer())
        s.go()

        self.assertTrue(gold in mock_connection._message)
        self.assertTrue(silver in mock_connection._message)
        self.assertTrue(bronze in mock_connection._message)
 def test_questioner_gives_its_ask(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     subject = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     self.assertEqual(subject.ask, "What's a Diorama?")
Ejemplo n.º 4
0
 def test_round_tells_player_scores_to_reset_scores_for_a_new_round_at_the_end_of_its_go(
         self):
     questions = [
         {
             'Round': 2,
             'Ask': 'What is your name?',
             'Answer': 'Sir Lancelot of Camelot'
         },
         {
             'Round': 2,
             'Ask': 'What is your quest?',
             'Answer': 'To seek the Holy Grail'
         },
         {
             'Round': 2,
             'Ask': 'What is your favorite color?',
             'Answer': 'Blue'
         },
     ]
     mock_player_scores = Player_Scores()
     s = Subject(Connection(), questions, Questions_Asked(),
                 mock_player_scores, Timer())
     s.end()
     self.assertEqual(mock_player_scores._next_round_called,
                      "Round Scores Reset")
Ejemplo n.º 5
0
    def test_round_runs_through_a_tiny_round_flow_example(self):
        questions = [{
            'Round': 1,
            'Ask': "What also floats in water?",
            'Answer': "A Duck!"
        }, {
            'Round': 1,
            'Ask':
            "What is the average airspeed velocity of an unladen swallow?",
            'Answer': "What do you mean? African or European?"
        }]
        mock_connection = Connection()
        mock_player_scores = Player_Scores()
        s = Subject(mock_connection, questions, Questions_Asked(),
                    mock_player_scores, Timer())

        with ThreadPoolExecutor(max_workers=2) as e:
            e.submit(s.go)
            e.submit(self.chat_thread, mock_connection)

        self.assertTrue("1" in mock_connection._message_list[0])
        self.assertEqual(questions[0]["Ask"], mock_connection._message_list[1])
        self.assertTrue(questions[1]["Ask"] in mock_connection._message_list)
        self.assertTrue(mock_player_scores._round_winners[0][0] in
                        mock_connection._message)
 def test_questioner_doesnt_care_if_there_are_extra_fields(self):
     question = {
         'Round': 1,
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!",
         'Answer2': 'D\'oh!'
     }
     Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
 def test_questioner_second_hint_returns_no_vowels_in_answer(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     actual = s.second_hint()
     self.assertEqual(actual, "_MG H_n! Ch_w__! Th_y'r_ _ll h_r_!")
 def test_questioner_first_hint_returns_2_out_of_3_chars_in_answer(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     actual = s.first_hint()
     self.assertEqual(actual, "O__ __n__C__w__!__h__'__ __l__e__!")
 def test_questioner_logs_that_it_is_done_with_its_question(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_questions_asked = Questions_Asked()
     s = Subject(Connection(), question, mock_questions_asked, Player_Scores(), Timer())
     s.end()
     self.assertEqual(mock_questions_asked._log[0], question)
 def test_questioner_identifies_a_correct_answer_inside_a_message(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     participant_answer = "I would say OMG Han! Chewie! They're all here! what do you think?"
     actual = s.check_answer(participant_answer)
     self.assertEqual(actual, True)
 def test_questioner_knows_itself_and_expects_strings_as_input(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     self.assertEqual(s.ask, "What's a Diorama?")
     self.assertEqual(type(s.ask), str)
     self.assertEqual(type(s.ask), str)
 def test_questioner_asks_a_question_to_the_chat_to_start(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     s = Subject(mock_connection, question, Questions_Asked(), Player_Scores(), Timer())
     s.start()
     self.assertEqual(mock_connection._message, "What's a Diorama?")
 def test_questioner_identifies_a_correct_answer_even_with_garbage_characters_interleaved(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     participant_answer = "O!M@G#H$a%n^?&C*(h)e_w-i+e=!{T}[h]e|y'r\\e:a;l\"l'<h>e,r.e/"
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     actual = s.check_answer(participant_answer)
     self.assertEqual(actual, True)
Ejemplo n.º 14
0
    def test_game_init_rounds_returns_an_empty_array_if_no_questions_are_given(
            self):
        initial_questions = []

        s = Subject(Connection(), initial_questions, Questions_Asked(),
                    Player_Scores(), Timer())
        actual_questions = s.init_rounds()

        self.assertEqual(actual_questions, initial_questions)
    def test_tuple_returns_the_configured_command_tuple(self):
        subject = Go("mocks/config.txt", "mocks/triviaset.csv",
                     Questions_Asked(), Player_Scores())

        command = subject.tuple()

        self.assertEqual(command[0], "!go")
        self.assertEqual(command[1], subject.run_the_next_trivia_round)
        self.assertEqual(command[2], ["admin_only"])
 def test_questioner_lets_the_chat_know_its_moving_on(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     s = Subject(mock_connection, question, Questions_Asked(), Player_Scores(), Timer())
     s.go()
     self.assertTrue(mock_connection._message in Chat.unanswered_questions)
 def test_questioner_identifies_a_correct_answer_ignoring_case(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     participant_answer = "OmG hAn! CheWIe! theY're all hEre!"
     actual = s.check_answer(participant_answer)
     self.assertEqual(actual, True)
 def test_questioner_identifies_a_correct_answer_ignoring_internal_whitespace(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     participant_answer = " \t \rOMGHan!   Chewie! \t They're all here!\r \n "
     actual = s.check_answer(participant_answer)
     self.assertEqual(actual, True)
 def test_questioner_identifies_an_incorrect_answer(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     s = Subject(Connection(), question, Questions_Asked(), Player_Scores(), Timer())
     participant_answer = "I don't know, some kind of goblin-man."
     actual = s.check_answer(participant_answer)
     self.assertEqual(actual, False)
    def test_go_command_logs_if_theres_an_error(self):
        spy = Spy_Log()
        s = Go("mocks/config.txt", "mocks/bad_triviaset.csv",
               Questions_Asked(), Player_Scores(), spy.log)

        mock_connection = Connection()
        _message = "irrelevant in this instance"
        s.run_the_next_trivia_round(mock_connection, _message)

        self.assertTrue("Ask" in spy._history[0] and "4" in spy._history[0])
 def test_questioner_ignores_incorect_answers_from_connection(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     mock_connection.last_response = ("trivvy_fan", "The Wrong Answer")
     s = Subject(mock_connection, question, Questions_Asked(), Player_Scores(), Timer())
     s.go()
     self.assertTrue(mock_connection._message in Chat.unanswered_questions)
 def test_questioner_includes_the_winners_name_when_they_answer_correctly_immediately(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     mock_connection.last_response = ("happy_lass", "OMG Han! Chewie! They're all here!")
     s = Subject(mock_connection, question, Questions_Asked(), Player_Scores(), Timer())
     s.go()
     self.assertTrue(mock_connection.last_response[0] in mock_connection._message)
Ejemplo n.º 23
0
    def test_game_clears_logs_if_it_reaches_the_end_of_the_game(self):
        questions = [{'Round': 3, 'Ask': 'Are you a god?', 'Answer': 'YES!'}]
        mock_questions_asked = Questions_Asked()

        s = Subject(Connection(), questions, mock_questions_asked,
                    Player_Scores(), Timer())
        s.start()
        s.end()

        self.assertEqual(mock_questions_asked._clear_received, True)
    def go_command_skips_running_the_next_trivia_round_if_theres_an_error(
            self):
        s = Go("mocks/config.txt", "mocks/bad_triviaset.csv",
               Questions_Asked(), Player_Scores(), dont_print)

        mock_connection = Connection()
        _message = "irrelevant in this instance"
        s.run_the_next_trivia_round(mock_connection, _message)

        self.assertEqual(mock_connection._message, 'No message recieved.')
 def test_questioner_records_the_winner_when_they_answer_correctly(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     mock_player_scores = Player_Scores()
     mock_connection.last_response = ("happy_lass", "OMG Han! Chewie! They're all here!")
     s = Subject(mock_connection, question, Questions_Asked(), mock_player_scores, Timer())
     s.go()
     self.assertEqual(mock_connection.last_response[0], mock_player_scores._score)
    def test_run_the_next_trivia_round_runs_a_whole_round(self):
        mock_player_scores = Player_Scores()
        s = Go("mocks/config.txt", "mocks/triviaset.csv", Questions_Asked(),
               mock_player_scores, dont_print)

        mock_connection = Connection()
        _message = "irrelevant in this instance"
        s.run_the_next_trivia_round(mock_connection, _message)

        winner = mock_player_scores._round_winners[0][0]
        self.assertTrue(winner in mock_connection._message)
 def test_questioner_does_not_record_the_player_when_they_answer_incorrectly(self):
     question = {
         'Ask': "What's a Diorama?",
         'Answer': "OMG Han! Chewie! They're all here!"
     }
     mock_connection = Connection()
     mock_player_scores = Player_Scores()
     mock_connection.last_response = ("wrong_man", "a model representing a scene with three-dimensional figures")
     s = Subject(mock_connection, question, Questions_Asked(), mock_player_scores, Timer())
     s.go()
     self.assertEqual("Not Yet Called.", mock_player_scores._score)
Ejemplo n.º 28
0
    def test_game_tells_players_to_reset_scores_for_a_new_game_at_the_end_of_the_game(
            self):
        questions = [{'Round': 3, 'Ask': 'Are you a god?', 'Answer': 'YES!'}]
        mock_player_scores = Player_Scores()

        s = Subject(Connection(), questions, Questions_Asked(),
                    mock_player_scores, Timer())
        s.start()
        s.end()

        self.assertEqual(mock_player_scores._next_game_called,
                         "Game Scores Reset")
Ejemplo n.º 29
0
    def test_game_list_by_rounds_doesnt_care_about_rounds_with_names(self):
        initial_questions = [{
            'Round': "Simpsons",
            'Ask': "What's a Diorama?",
            'Answer': "OMG Han! Chewie! They're all here!"
        }, {
            'Round': "Grail",
            'Ask': 'What is your name?',
            'Answer': 'Sir Lancelot of Camelot'
        }, {
            'Round': "Grail",
            'Ask': 'What is your quest?',
            'Answer': 'To seek the Holy Grail'
        }, {
            'Round': "Grail",
            'Ask': 'What is your favorite color?',
            'Answer': 'Blue'
        }, {
            'Round': "Ghost",
            'Ask': 'Are you a god?',
            'Answer': 'YES!'
        }]
        expected_questions = [
            [{
                'Round': "Simpsons",
                'Ask': "What's a Diorama?",
                'Answer': "OMG Han! Chewie! They're all here!"
            }],
            [{
                'Round': "Grail",
                'Ask': 'What is your name?',
                'Answer': 'Sir Lancelot of Camelot'
            }, {
                'Round': "Grail",
                'Ask': 'What is your quest?',
                'Answer': 'To seek the Holy Grail'
            }, {
                'Round': "Grail",
                'Ask': 'What is your favorite color?',
                'Answer': 'Blue'
            }],
            [{
                'Round': "Ghost",
                'Ask': 'Are you a god?',
                'Answer': 'YES!'
            }],
        ]

        s = Subject(Connection(), initial_questions, Questions_Asked(),
                    Player_Scores(), Timer())
        actual_questions = s.list_by_rounds(initial_questions)

        self.assertEqual(actual_questions, expected_questions)
Ejemplo n.º 30
0
    def test_game_tells_players_to_score_game_winners_at_the_end_of_the_game(
            self):
        questions = [{'Round': 3, 'Ask': 'Are you a god?', 'Answer': 'YES!'}]
        mock_player_scores = Player_Scores()

        s = Subject(Connection(), questions, Questions_Asked(),
                    mock_player_scores, Timer())
        s.start()
        s.end()

        self.assertEqual(mock_player_scores._winner,
                         mock_player_scores._game_winners[0][0])