def test_questioner_has_a_strict_oder_to_its_message_flow(self):
     question = {
         'Ask': "What also floats in water?",
         'Answer': "A Duck!"
     }
     mock_connection = Connection()
     mock_timer = Timer()
     s = Subject(mock_connection, question, Questions_Asked(), Player_Scores(), Timer())
     s.go()
     self.assertEqual(len(mock_connection._message_list), 4)
     self.assertEqual(s.ask, mock_connection._message_list[0])
     self.assertEqual(s.first_hint(), mock_connection._message_list[1])
     self.assertEqual(s.second_hint(), mock_connection._message_list[2])
     self.assertTrue(mock_connection._message_list[3] in Chat.unanswered_questions)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo 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")
 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_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_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())
Exemplo n.º 8
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_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)
 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_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_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_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_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_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_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)
Exemplo n.º 18
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)
 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)
Exemplo n.º 20
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 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)
Exemplo n.º 22
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)
Exemplo n.º 23
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])
Exemplo n.º 24
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")
Exemplo n.º 25
0
    def test_game_list_by_rounds_groups_rounds_by_when_they_appear_in_the_list(
            self):
        initial_questions = [{
            'Round': 2,
            'Ask': 'What is your favorite color?',
            'Answer': 'Blue'
        }, {
            'Round': 5,
            'Ask': 'Are you a god?',
            'Answer': 'YES!'
        }, {
            'Round': 2,
            'Ask': 'What is your name?',
            'Answer': 'Sir Lancelot of Camelot'
        }, {
            'Round': 1,
            'Ask': "What's a Diorama?",
            'Answer': "OMG Han! Chewie! They're all here!"
        }, {
            'Round': 2,
            'Ask': 'What is your quest?',
            'Answer': 'To seek the Holy Grail'
        }]
        expected_questions = [[{
            'Round': 2,
            'Ask': 'What is your favorite color?',
            'Answer': 'Blue'
        }, {
            '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': 5,
            'Ask': 'Are you a god?',
            'Answer': 'YES!'
        }],
                              [{
                                  'Round': 1,
                                  'Ask': "What's a Diorama?",
                                  'Answer':
                                  "OMG Han! Chewie! They're all here!"
                              }]]

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

        self.assertEqual(actual_questions, expected_questions)
    def test_questioner_times_out_when_no_one_answers_correctly(self):
        question = {
            'Ask': "What also floats in water?",
            'Answer': "A Duck!"
        }
        mock_connection = Connection()
        s = Subject(mock_connection, question, Questions_Asked(), Player_Scores(), Timer())

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

        self.assertTrue(mock_connection._message in Chat.unanswered_questions)
    def test_questioner_includes_the_winners_name_when_they_answer_correctly_amongst_a_stream_of_chatter(self):
        question = {
            'Ask': "What also floats in water?",
            'Answer': "A Duck!"
        }
        mock_connection = Connection()
        s = Subject(mock_connection, question, Questions_Asked(), Player_Scores(), Timer())

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

        self.assertTrue("Arthur" in mock_connection._message)
Exemplo n.º 28
0
    def test_game_organizes_questions_into_rounds_for_each_round_instance_on_start(
            self):
        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!'
        }]

        subject = Subject(Connection(), questions, Questions_Asked(),
                          Player_Scores(), Timer())
        subject.start()

        self.assertEqual(subject.rounds[0].questioners[0].ask,
                         "What's a Diorama?")
        self.assertEqual(subject.rounds[1].questioners[0].ask,
                         'What is your name?')
        self.assertEqual(subject.rounds[1].questioners[1].ask,
                         'What is your quest?')
        self.assertEqual(subject.rounds[1].questioners[2].ask,
                         'What is your favorite color?')
        self.assertEqual(subject.rounds[2].questioners[0].ask,
                         'Are you a god?')
Exemplo n.º 29
0
    def test_game_lets_the_chat_know_the_game_is_over_with_who_won(self):
        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_connection = Connection()
        mock_player_scores = Player_Scores()
        mock_questions_asked = Questions_Asked()
        gold = f"{mock_player_scores._game_winners[0][0]}: {mock_player_scores._game_winners[0][1]}"
        silver = f"{mock_player_scores._game_winners[1][0]}: {mock_player_scores._game_winners[1][1]}"
        bronze = f"{mock_player_scores._game_winners[2][0]}: {mock_player_scores._game_winners[2][1]}"

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

        self.assertTrue(gold in mock_connection._message)
        self.assertTrue(silver in mock_connection._message)
        self.assertTrue(bronze in mock_connection._message)
Exemplo n.º 30
0
 def test_round_lets_the_chat_know_a_new_round_started_by_sending_its_name(
         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()
     s = Subject(mock_connection, questions, Questions_Asked(),
                 Player_Scores(), Timer())
     s.start()
     self.assertTrue("2" in mock_connection._message)