Exemple #1
0
 def test_play_game_2_hands(self):
     #redirect output to silence print statements during running of tests
     student_deal_hand = ps3.deal_hand
     
     saved_stdout = sys.stdout
     #create place to save output
     out = StringIO()
     sys.stdout = out
     #save previous standard ouptut
     h1 = {'s':1, 'c':1, 'i':1, 'p':1, 'r':1, 'k':1, '@':1}
     h2 = {'d':1, 'a':1, 'e':1, 'l':1, 'f':1, 'z':1, '@':1}
     
     ps3.deal_hand = mock.Mock(side_effect=[h1, h2])
     inputs = ['2', 'no', 'sick', '*END*', 'no', 'no', 'deal', '*END*', 'no']
     correct_answer = 30
     
     try: #mock input for game
         with mock.patch('builtins.input', side_effect=inputs):
             result = ps3.play_game(word_list)
             if result == None:
                 sys.stdout = saved_stdout
                 self.fail(NOT_IMPLEMENTED)
         self.assertEqual(result, correct_answer, WRONG_SCORE_GAME %(inputs, [h1,h2], result, correct_answer))    
         ps3.deal_hand = student_deal_hand
     except StopIteration as e:
         sys.stdout = saved_stdout
         ps3.deal_hand = student_deal_hand
         self.fail(STOP_ITER_MSG_GAME %(inputs, [h1,h2]))
     except:
         sys.stdout = saved_stdout
         ps3.deal_hand = student_deal_hand
         raise
     ps3.deal_hand = student_deal_hand
     sys.stdout = saved_stdout 
Exemple #2
0
 def test_play_game_with_replay(self):
     #redirect output to silence print statements during running of tests
     saved_stdout = sys.stdout
     student_deal_hand = ps3.deal_hand
     #create place to save output
     out = StringIO()
     sys.stdout = out
     #save previous standard ouptut
     h1 = {'a':1, 'c':1, 'i':1, 'p':1, 'r':1, 't':1, '@':1}
     
     ps3.deal_hand = mock.Mock(side_effect=[h1])
     inputs = ['1', 'no', 'car', 'pit', '*END*', 'yes', 'ca@', 'tip', '*END*']
     result = -1    
     try:
         #mock input for game
         with mock.patch('builtins.input', side_effect=inputs):
             result = ps3.play_game(word_list)
             if result == None:
                 sys.stdout = saved_stdout
                 self.fail(NOT_IMPLEMENTED)     
         
         self.assertEqual(result, 45, WRONG_SCORE_GAME %(inputs, h1, result, 45))
         ps3.deal_hand = student_deal_hand
     except StopIteration as e:
         sys.stdout = saved_stdout
         ps3.deal_hand = student_deal_hand
         self.fail(STOP_ITER_MSG %(inputs, h1))
     except:
         ps3.deal_hand = student_deal_hand
         sys.stdout = saved_stdout 
         raise
     #change standard output to be saved
     ps3.deal_hand = student_deal_hand
     sys.stdout = saved_stdout 
Exemple #3
0
    def test_play_game_with_substitution_and_replay(self):
        #redirect output to silence print statements during running of tests
        saved_stdout = sys.stdout
        student_deal_hand = ps3.deal_hand
        #create place to save output
        out = StringIO()
        sys.stdout = out
        #save previous standard ouptut
        h1 = {'a':1, 'c':1, 'i':1, 'p':1, 'r':1, 't':1, '@':1}
        h2 = {'f':2, 'a':1, 'o':1, 'u':1, 't':1, '@':1}
        replaced_letter = {'d':2, 'a':1, 'o':1, 'u':1, 't':1, '@':1}
        old_substitute = ps3.substitute_hand
        ps3.deal_hand = mock.Mock(side_effect=[h1, h2])
        ps3.substitute_hand = mock.Mock(side_effect=[replaced_letter])
        inputs = ['2', 'no', 'part', '@ic', 'no', 'yes', 'f', 'out', '*END*', 'yes', 'dad', 'out', '*END*']
            

        try: #mock input for game
            with mock.patch('builtins.input', side_effect=inputs):
                result = ps3.play_game(word_list)
                if result == None:
                    sys.stdout = saved_stdout
                    self.fail(NOT_IMPLEMENTED)
            self.assertEqual(result, 103, WRONG_SCORE_GAME_REPLACE %(inputs, [h1,h2], 'd', result, 103))   
            ps3.substitute_hand = old_substitute
            ps3.deal_hand = student_deal_hand
        except StopIteration as e:
            sys.stdout = saved_stdout
            ps3.deal_hand = student_deal_hand
            ps3.substitute_hand = old_substitute
            self.fail(STOP_ITER_MSG_GAME %(inputs, [h1,h2]))
        except:
            sys.stdout = saved_stdout
            ps3.deal_hand = student_deal_hand
            ps3.substitute_hand = old_substitute
            raise
        sys.stdout = saved_stdout 
        ps3.deal_hand = student_deal_hand
        ps3.substitute_hand = old_substitute