Example #1
0
    def test_do_command(self):
        with open('test_output2.txt', 'w') as text_file:
            yes_no_options = ["y", "yes", "no", "n"]
            for word in yes_no_options:
                #Game initialization
                game = Game()
                load_advent_dat(game)
                game.start()
                #No response
                if word in ["no", "n"]:
                    game.yesno_callback = self.assertFalse
                    text_file.write("Output for {0}: {1}\n".format(
                        word, False))
                    game.do_command([word])
                elif word in ["y", "yes", "yessir", "yes please"]:
                    game.yesno_callback = self.assertTrue
                    text_file.write("Output for {0}: {1}\n".format(word, True))
                    game.do_command([word])

            invalidWordList = ['stop', 'maybe', 'actually']
            for words in invalidWordList:
                game.yesno_callback = self.assertIsNotNone
                #gtext_file.write("Output for {0}: {1}\n".format(word, True))
                value = str(game.do_command([words]))
                text_file.write("Output for {0}: {1}\n".format(words, value))
Example #2
0
 def test_yes_no_pass(self):
     #Output manager for this test
     with open('test_output2.txt', 'w') as text_file:
         #Arbitrary array of valid/invalid yes/no values
         yes_no_options = [
             "y", "yes", "no", "maybe", "n", "yessir", "yes please", "stop"
         ]
         for word in yes_no_options:
             #Game initialization
             game = Game()
             load_advent_dat(game)
             game.start()
             #No response
             if word in ["no", "n"]:
                 game.yesno_callback = self.assertFalse
                 text_file.write("Output for {0}: {1}\n".format(
                     word, False))
                 game.do_command([word])
             #Yes response
             elif word in ["y", "yes", "yessir", "yes please"]:
                 game.yesno_callback = self.assertTrue
                 text_file.write("Output for {0}: {1}\n".format(word, True))
                 game.do_command([word])
             #Invalid response
             else:
                 text_file.write("Output for {0}: {1}".format(
                     word, str(game.do_command([word]))))
Example #3
0
    def test_do_commands_for_the_case_none(self):
        game = Game()
        load_advent_dat(game)
        game.start()
	# This will test if argument to callback is invalid
        game.yesno_callback = self.assertIsNone
        game.do_command(['None'])
Example #4
0
 def test_intransitive_commands_should_not_throw_exceptions(self):
     for word in self.words:
         game = Game()
         load_advent_dat(game)
         game.start()
         game.do_command(['no'])  # WOULD YOU LIKE INSTRUCTIONS?
         game.do_command([word])
Example #5
0
    def test_do_command_pass(self):
	    game = Game()
 	    load_advent_dat(game)
	    game.start()
            # This will test if argument to callback is True
            game.yesno_callback = self.assertTrue
 	    # Run the test for the answer 'y'
  	    game.do_command(['y'])
            
            game.yesno_callback = self.assertTrue
            # Run the test for the answer 'yes'
            game.do_command(['yes'])
	
            # This will test if argument to callback is False
            game.yesno_callback = self.assertFalse
            # Run the test for the answer 'n'
            game.do_command(['n'])

            game.yesno_callback = self.assertFalse
            # Run the test for the answer 'no'
            game.do_command(['no'])

            # Run the test for the invalid input, for example 'yyes' 
            game.yesno_callback = self.assertIsNone
            game.do_command(['yyes'])
 
            # Run the test for the invalid input, for example 'nno'
            game.yesno_callback = self.assertIsNone
            game.do_command(['nno'])
Example #6
0
    def test_do_command(self):
        # Set up the test case
        testGame = Game()
        load_advent_dat(testGame)
        testGame.start()

        affirmativeAnswers = ['yes','y']
        negativeAnswers = ['no','n']
        #Use as other possible answers all the words in the vocabulary plus
        #some malformed answers.
        otherAnswers = [otherAnswer for otherAnswer 
                        in testGame.vocabulary.keys() 
                        if otherAnswer not in affirmativeAnswers+negativeAnswers ]
        otherAnswers.extend(['asdf','fgjh', ' '])

        for testAnswer in affirmativeAnswers:
            self.setUp_test_do_command(testGame)
            testGame._do_command([testAnswer])
            self.assertTrue(self._do_command_testResult)
        
        for testAnswer in negativeAnswers:    
            self.setUp_test_do_command(testGame)
            testGame._do_command([testAnswer])
            self.assertFalse(self._do_command_testResult)  
        
        for testAnswer in otherAnswers: 
            self.setUp_test_do_command(testGame)
            testGame._do_command([testAnswer])
            self.assertIsNone(self._do_command_testResult)  
Example #7
0
 def test_intransitive_commands_should_not_throw_exceptions(self):
     for word in self.words:
         game = Game()
         load_advent_dat(game)
         game.start()
         game.do_command(['no'])  # WOULD YOU LIKE INSTRUCTIONS?
         game.do_command([word])
Example #8
0
 def test_do_command(self):
     
     possible_answers = ["y", "n", "yes", "no"]
     wrong_answers = ["wrong", "maybe", "later"]
     
     
     for answer in possible_answers:
         
         game = Game()
         load_advent_dat(game)
                  
         # This will test if argument to callback is True
         game.yesno_callback = self.assertTrue
         
         game.start()
         
         # Run the actual test
         game.do_command([answer])
         
     for answer in wrong_answers:
         
         game = Game()
         load_advent_dat(game)
                  
         # This will test if argument to callback is True
         game.yesno_callback = self.assertFalse
         
         game.start()
         
         # Run the actual test
         game.do_command([answer])
Example #9
0
    def test_do_commands_for_the_case_no(self):
        game = Game()
        load_advent_dat(game)
        game.start()
	# This will test if argument to callback is False
        game.yesno_callback = self.assertFalse
        game.do_command(['no'])
Example #10
0
    def test_do_command(self):
	#initialize game
	game = Game()
	load_advent_dat(game)
	game.start()

	#test callback True and valid answer 'y' and 'yes'
	#test if argument to callback is true
	game.yesno_callback = self.assertTrue
	#run the actual test
	game.do_command(['y'])
	
	game.yesno_callback = self.assertTrue
	game.do_command(['yes'])

	#test callback False and valid answer 'n' and 'no'
	game.yesno_callback = self.assertFalse
	game.do_command(['n'])
	
	game.yesno_callback = self.assertFalse
	game.do_command(['no'])

	#test callback is none and invalid answer 'aaa'
	game.yesno_callback = self.assertIsNone
	game.do_command(['aaa'])
Example #11
0
 def test_valid_and_invalid_yes_no_answers(self):
     game = Game();
     load_advent_dat(game)
     game.start()
           
     #Test all valid 'yes' answers
     #'y'
     game.yesno_callback = self.assertTrue
     game.do_command(['y'])
     #'yes'
     game.yesno_callback = self.assertTrue
     game.do_command(['yes'])
     
     #Test all valid 'no' answers
     #'n'
     game.yesno_callback = self.assertFalse
     game.do_command(['n'])
     #'no'
     game.yesno_callback = self.assertFalse
     game.do_command(['no'])
     
     #Test other invalid answers
     #random word 'ny'
     game.yesno_callback = self.assertIsNotNone
     game.do_command(['ny'])
     #random word 'idk'
     game.yesno_callback = self.assertIsNotNone
     game.do_command(['idk'])
Example #12
0
 def test_do_commands_for_the_case_no(self):
     game = Game()
     load_advent_dat(game)
     game.start()
     # This will test if argument to callback is False
     game.yesno_callback = self.assertFalse
     game.do_command(['no'])
Example #13
0
    def test_do_command_pass(self):
        game = Game()
        load_advent_dat(game)
        game.start()
        # This will test if argument to callback is True
        game.yesno_callback = self.assertTrue
        # Run the test for the answer 'y'
        game.do_command(['y'])

        game.yesno_callback = self.assertTrue
        # Run the test for the answer 'yes'
        game.do_command(['yes'])

        # This will test if argument to callback is False
        game.yesno_callback = self.assertFalse
        # Run the test for the answer 'n'
        game.do_command(['n'])

        game.yesno_callback = self.assertFalse
        # Run the test for the answer 'no'
        game.do_command(['no'])

        # Run the test for the invalid input, for example 'yyes'
        game.yesno_callback = self.assertIsNone
        game.do_command(['yyes'])

        # Run the test for the invalid input, for example 'nno'
        game.yesno_callback = self.assertIsNone
        game.do_command(['nno'])
Example #14
0
 def test_do_commands_for_the_case_none(self):
     game = Game()
     load_advent_dat(game)
     game.start()
     # This will test if argument to callback is invalid
     game.yesno_callback = self.assertIsNone
     game.do_command(['None'])
Example #15
0
def loop():
    parser = argparse.ArgumentParser(
        description='Adventure into the Colossal Caves.',
        prog='{} -m adventure'.format(os.path.basename(executable)))
    parser.add_argument('savefile',
                        nargs='?',
                        help='The filename of game you have saved.')
    args = parser.parse_args()

    if args.savefile is None:
        game = Game()
        load_advent_dat(game)
        game.start()
        baudout(game.output)
    else:
        game = Game.resume(args.savefile)
        baudout('GAME RESTORED\n')

    #change raw_input() to input()
    #2.7 to 3.5
    while not game.is_finished:
        line = input('> ')
        words = re.findall(r'\w+', line)
        if words:
            baudout(game.do_command(words))
Example #16
0
    def test_yes_no_answers(self):
        '''This is an added test to check valid yes/ no answers for the the Game class'''
        for word in self.words:
            YESNO_RESPONSE = ['y','yes','n','no','what']
            output = open('output2.txt', 'w')
            for ans in YESNO_RESPONSE:
                game = Game()
                load_advent_dat(game)
                game.start()
                if ans[0] == 'y':
                    output_string = ans + " is true \n" 
                    output.write(output_string)
                    game.yesno_callback = self.assertTrue
                    game.do_command([ans])

                elif ans[0] == 'n':
                    output_string = ans + " is false \n" 
                    output.write(output_string)
                    game.yesno_callback = self.assertFalse
                    game.do_command([ans])

                else:
                    output_string = ans + "\n"
                    output.write(output_string)
                    do_command_output = game.do_command([ans])
                    output.write(do_command_output)
Example #17
0
 def test_transitive_commands_should_not_throw_exceptions(self):
     for word in self.words:
         game = Game()
         load_advent_dat(game)
         game.start()
         game.do_command(["no"])  # WOULD YOU LIKE INSTRUCTIONS?
         game.do_command(["enter"])  # so we are next to lamp
         game.do_command([word, "lamp"])
 def test_transitive_commands_should_not_throw_exceptions(self):
     for word in self.words:
         game = Game()
         load_advent_dat(game)
         game.start()
         game.do_command(['yes'])  # WOULD YOU LIKE INSTRUCTIONS?
         game.do_command(['enter'])  # so we are next to lamp
         game.do_command([word, 'lamp'])
Example #19
0
 def test_do_commands_for_the_case_y(self):
     game = Game()
     load_advent_dat(game)
     game.start()
     # This will test if argument to callback is True
     game.yesno_callback = self.assertTrue
     # Run the actual test
     game.do_command(['y'])
Example #20
0
 def setUp(self):
     game = Game()
     load_advent_dat(game)
     self.words = set(w.synonyms[0].text for w in game.vocabulary.values())
     self.words.remove('suspend')
     self.answers_yes = ('y','yes','Y','Yes','yEs','yeS','YEs','YeS','yES','YES','ye','Ye','yE','YE')
     self.answers_no = ('n','no','N','No','nO','NO')
     self.answers_whether_invalid = ('>',':','$','@!~?',' ')
Example #21
0
 def test_invalid_commands_should_not_throw_exceptions(self):
     invalid_words = ['maybe', 'perhaps', 'dunno']
     for word in invalid_words:
         game = Game()
         load_advent_dat(game)
         game.start()
         game.yesno_callback = self.assertIsNone
         game.do_command([word])
Example #22
0
 def test_valid_yes_commands_should_return_true(self):
     valid_yes_words = ['yes', 'y']
     for word in valid_yes_words:
         game = Game()
         load_advent_dat(game)
         game.start()
         game.yesno_callback = self.assertTrue
         game.do_command([word])
Example #23
0
    def test_do_commands_for_the_case_y(self):
        game = Game()
        load_advent_dat(game)
        game.start()
	# This will test if argument to callback is True
	game.yesno_callback = self.assertTrue
	# Run the actual test
	game.do_command(['y'])
Example #24
0
 def test_valid_no_commands_should_return_false(self):
     valid_no_words = ['no', 'n']
     for word in valid_no_words:
         game = Game()
         load_advent_dat(game)
         game.start()
         game.yesno_callback = self.assertFalse
         game.do_command([word])
Example #25
0
 def test_do_command_yesno_callback_yes(self):
     # Test _do_command when command is yes, the yesno_callback is True.
     game = Game()
     load_advent_dat(game)
     game.start()
     # This will test if argument to callback is True.
     game.yesno_callback = self.assertTrue
     # Run the actual test
     game.do_command(['yes'])
Example #26
0
 def setUp(self):
     game = Game()
     load_advent_dat(game)
     self.words = set(w.synonyms[0].text for w in game.vocabulary.values())
     self.words.remove('suspend')
     self.answers_yes = ('y', 'yes', 'Y', 'Yes', 'yEs', 'yeS', 'YEs', 'YeS',
                         'yES', 'YES', 'ye', 'Ye', 'yE', 'YE')
     self.answers_no = ('n', 'no', 'N', 'No', 'nO', 'NO')
     self.answers_whether_invalid = ('>', ':', '$', '@!~?', ' ')
Example #27
0
 def test_do_command_yesno_callback_invalid_words(self):
     # Test _do_command when command is invalid words, the yesno_callback is None.
     game = Game()
     load_advent_dat(game)
     game.start()
     # This will test if argument to callback is None.
     self.assertTrue(game.yesno_callback, None)
     # Run the actual test
     game.do_command(['invalidwords'])
Example #28
0
 def test_do_command_yesno_callback_no(self):
     # Test _do_command when command is no, the yesno_callback is False.
     game = Game()
     load_advent_dat(game)
     game.start()
     # This will test if argument to callback is False.
     game.yesno_callback = self.assertFalse
     # Run the actual test
     game.do_command(['no'])
Example #29
0
 def test_do_commands_with_invalid_answer(self):
     # Test when command is invalid, the yesno_call is None.
     game = Game()
     load_advent_dat(game)
     game.start()
     # This will test if argument to callback is None
     self.assertTrue(game.yesno_callback, None)
     # Run the actual test
     game.do_command(['husdyan'])
Example #30
0
 def test_do_commands_with_answer_n(self):
     # Test when command is n, the yesno_call is False.
     game = Game()
     load_advent_dat(game)
     game.start()
     # This will test if argument to callback is False
     game.yesno_callback = self.assertFalse
     # Run the actual test
     game.do_command(['n'])
Example #31
0
 def test_do_commands_with_invalid_answer(self):
     # Test when command is invalid, the yesno_call is None.
     game = Game()
     load_advent_dat(game)
     game.start()
     # This will test if argument to callback is None
     self.assertTrue(game.yesno_callback, None)
     # Run the actual test
     game.do_command(['husdyan'])
Example #32
0
 def test_do_commands_with_answer_no(self):
     # Test when command is no, the yesno_call is False.
     game = Game()
     load_advent_dat(game)
     game.start()
     # This will test if argument to callback is False
     game.yesno_callback = self.assertFalse
     # Run the actual test
     game.do_command(['no'])
Example #33
0
 def test_do_commands_with_answer_yes(self):
     # Test when command is yes, the yesno_call is True.
     game = Game()
     load_advent_dat(game)
     game.start()
     # This will test if argument to callback is True
     game.yesno_callback = self.assertTrue
     # Run the actual test
     game.do_command(['yes'])
Example #34
0
 def test_all_yes_commands(self):
     yes_commands = ['','y','yes','ye','yessss']
     for affirmative_string in yes_commands:
         game = Game()
         load_advent_dat(game)
         game.start()
         # This will test if argument to callback is True
         game._do_command([affirmative_string])  # WOULD YOU LIKE INSTRUCTIONS?
         # Run the actual test
         game.yesno_callbakc = self.assertTrue
Example #35
0
 def test_all_no_commands(self):
     no_commands = ['','n','no','nn','nooooo']
     for negative_string in no_commands:
         game = Game()
         load_advent_dat(game)
         game.start()
         # This will test if argument to callback is True
         game._do_command([negative_string])  # WOULD YOU LIKE INSTRUCTIONS?
         # Run the actual test
         game.yesno_callbakc = self.assertTrue
Example #36
0
 def test_do_command_should_not_throw_excpetions(self): #Test valid Yes/No inputs when yesno_calback attribute is set
         YESNO_ANSWERS = {'y': True, 'yes': True, 'n': False, 'no': False}
         for answer in YESNO_ANSWERS:
             game = Game()
             load_advent_dat(game)
             game.start()
             if answer in ['y','yes']:    
                game.yesno_callback = self.assertTrue 
                if answer in ['n','no']:    
                 game.yesno_callback = self.assertFalse
Example #37
0
    def test_yes_answers(self):
        # Checking the 'yes' response
        test_commands_yes = ["", "y", "ye", "yes", "x", "n"]
        for test_string in test_commands_yes:
            game = Game()
            load_advent_dat(game)
            game.start()

            game.yesno_callback = self.assertTrue

            game.do_command([test_string])
Example #38
0
    def test_no_answers(self):
        # Checking the 'no' response
        test_commands_no = ["", "n", "no", "p"]
        for test_string in test_commands_no:
            game = Game()
            load_advent_dat(game)
            game.start()

            game.yesno_callback = self.assertFalse

            game.do_command([test_string])
Example #39
0
 def test_do_command_method_for_yesno_answers(self):
     
         game = Game()                          # Instance creation for the Game() class   
         load_advent_dat(game)
         game.start()
         game.yesno_callback = self.assertTrue  # This will test if argument to callback is True
         game.do_command(['y'])                 # 'y' is passed to 'do_command' method - To test the 'y' case 
         game.yesno_callback = self.assertTrue  # This will test if argument to callback is True
         game.do_command(['yes'])               # 'yes' is passed to 'do_command' method - To test the 'yes' case
         game.yesno_callback = self.assertFalse # This will test if argument to callback is False
         game.do_command(['n'])                 # 'n' is passed to 'do_command' method - To test the 'n' case
         game.yesno_callback = self.assertFalse # This will test if argument to callback is False
         game.do_command(['no'])                # 'no' is passed to 'do_command' method - To test the 'no' case
Example #40
0
 def test_do_command(self):
      game = Game()
      load_advent_dat(game)
      game.yesno_callback = self.assertTrue
      game.do_command(['y'])
      game.yesno_callback = self.assertTrue 
      game.do_command(['yes'])
      game.yesno_callback = self.assertFalse
      game.do_command(['n'])
      game.yesno_callback = self.assertFalse 
      game.do_command(['no'])
      game.yesno_callback = self.assertIsNotNone 
      game.do_command(['word'])  
Example #41
0
 def test_do_command(self):
     game = Game()
     load_advent_dat(game)
     game.yesno_callback = self.assertTrue
     game.do_command(['y'])
     game.yesno_callback = self.assertTrue
     game.do_command(['yes'])
     game.yesno_callback = self.assertFalse
     game.do_command(['n'])
     game.yesno_callback = self.assertFalse
     game.do_command(['no'])
     game.yesno_callback = self.assertIsNotNone
     game.do_command(['word'])
Example #42
0
 def test_do_commands(self):
     yes_no_list= ["yes","y","no","n"]
     wrong_words= ["yea!", "Nope", "Noway", "You betcha", "^!@#$%^{}|}{}|~&*C"]
     for word in wrong_words:
         game = Game()
         load_advent_dat(game)
         game.yesno_callback = self.assertTrue
         game.start()
         game.do_command([word])
         
     for word in yes_no_list:
         game = Game()
         load_advent_dat(game)
         game.yesno_callback = self.assertTrue
         game.start()
         game.do_command([word])
Example #43
0
    def test__do_command_in_Game_class_is_correct_for_all_valid_answers(self):
        answers_to_test = ['yes','y','no','n']
        for answer in answers_to_test:
            game = Game()
            load_advent_dat(game)
            game.start()

            if answer in ['y', 'yes']:
                game.yesno_callback = self.assertTrue
                game.do_command([answer])
            
            elif answer in ['n', 'no']:
                game.yesno_callback = self.assertFalse
                game.do_command([answer])

            else:
                pass
Example #44
0
    def test_yesno_list_in_do_commands(self):
	acceptable_yesno_words=["yes","no","y","n","ye"]
	bad_yesno_words = ["nope","noooooo","nooo","!@$%^&*", "hell no", "for sure"]
	
	for word in acceptable_yesno_words:
	    game=Game()
	    load_advent_dat(game)
            game.yesno_callback = self.assertFalse
	    game.start()
	    game.do_command([word])

        for word in bad_yesno_words:
            game=Game()
            load_advent_dat(game)
            game.yesno_callback = self.assertTrue
            game.start()
            game.do_command([word])
Example #45
0
 def test_yes_no_input_handling(self):
     game = Game()
     load_advent_dat(game)
     
     YESNO_ANSWERS = {'y': True, 'yes': True, 'n': False, 'no': False}
     for input_word in YESNO_ANSWERS.keys():
         build_assert_string = 'assert' + str(YESNO_ANSWERS[input_word])
         game.yesno_callback = getattr(self, build_assert_string)
         game.do_command([input_word])
         
     INVALID_ANSWERS = ['maybe', 'IDK','what would you do?','other!)@#_random_135l_string']
     message_for_invalid_input = 'Please answer the question.'
     expected_output = message_for_invalid_input.upper() + '\n'
     for invalid_input_word in INVALID_ANSWERS:
         game.yesno_callback = getattr(self, 'assertEqual')
         game.do_command([invalid_input_word])
         self.assertEqual(game.output, expected_output)
Example #46
0
    def test_do_commands(self):
        yes_no_list = ["yes", "y", "no", "n"]
        wrong_words = [
            "yea!", "Nope", "Noway", "You betcha", "^!@#$%^{}|}{}|~&*C"
        ]
        for word in wrong_words:
            game = Game()
            load_advent_dat(game)
            game.yesno_callback = self.assertTrue
            game.start()
            game.do_command([word])

        for word in yes_no_list:
            game = Game()
            load_advent_dat(game)
            game.yesno_callback = self.assertTrue
            game.start()
            game.do_command([word])
Example #47
0
    def test_yes_no_do_command(self):
        for word in self.words:
            game = Game()
            load_advent_dat(game)
            game.start()

            # test for valid inputs
            game.yesno_callback = self.assertTrue
            game.do_command(['y'])
            game.yesno_callback = self.assertTrue
            game.do_command(['yes'])
            game.yesno_callback = self.assertFalse
            game.do_command(['n'])
            game.yesno_callback = self.assertFalse
            game.do_command(['no'])

            # test for invalid inputs
            game.yesno_callback = self.assertIsNone
            game.do_command(['not_y_n'])
Example #48
0
    def test_yesno_callback_with_entry_yes_no_invalid(self):
        game = Game()
        load_advent_dat(game)
        game.start()
        
        # to test whether the yesno_callback is True when entry is 'yes' or 'y'
        for yes_entry in ['yes','y']:
            game.yesno_callback = self.assertTrue
            game.do_command([yes_entry])
        
        # to test whether the yesno_callback is False when entry is 'no' or 'n'
        for no_entry in ['no','n']:
            game.yesno_callback = self.assertFalse
            game.do_command([no_entry])

        # to test whether the yesno_callback is None when entry is invalid
        for invalid_entry in ['nossss','yss']:
            game.yesno_callback = self.assertIsNone
            game.do_command([invalid_entry])
Example #49
0
    def test_if_do_command_is_valid_for_all_inputs(self):
        game = Game()
        load_advent_dat(game)
        game.start()
        # This will test if argument to callback is True
        game.yesno_callback = self.assertTrue
        # Run the actual test
        game.do_command(['y'])

        game.yesno_callback = self.assertTrue
        game.do_command(['yes'])

        # test 'no' inputs
        game.yesno_callback = self.assertFalse
        game.do_command(['no'])
        game.yesno_callback = self.assertFalse
        game.do_command(['n'])

        # test invalid inputs
        game.yesno_callback = self.assertIsNone
        game.do_command(['wowwowow'])
Example #50
0
    def test_do_command_yes_no_check(self):

        YES_VALID_OPTIONS = ['y', 'yes']
        NO_VALID_OPTIONS = ['n', 'no']
        POSSIBLE_INVALID_OPTIONS = [
            'ye', 'YES', 'YESE', 'YEAH', 'yese', 'NO', 'maybe', '', '$*^%^&+++'
        ]

        for possible_answer in YES_VALID_OPTIONS:
            game = Game()
            load_advent_dat(game)
            game.start()
            game.yesno_callback = self.assertTrue
            game._do_command([possible_answer])

        for possible_answer in NO_VALID_OPTIONS:
            game = Game()
            load_advent_dat(game)
            game.start()
            game.yesno_callback = self.assertFalse
            game._do_command([possible_answer])

        for possible_answer in POSSIBLE_INVALID_OPTIONS:
            game = Game()
            load_advent_dat(game)
            game.start()
            game.yesno_callback = self.assertIsNone
            game._do_command([possible_answer])
Example #51
0
    def test_do_command_is_correct_for_valid_or_invalid_user_yesno_answers(
            self):

        for answer1 in self.answers_yes:
            game = Game()
            load_advent_dat(game)
            game.start()
            # This will test if argument to callback is True
            game.yesno_callback = self.assertTrue
            # Run the actual test
            game.do_command(answer1)

        for answer2 in self.answers_no:
            game = Game()
            load_advent_dat(game)
            game.start()
            # This will test if argument to callback is False
            game.yesno_callback = self.assertFalse
            # Run the actual test
            game.do_command(answer2)

        for answer3 in self.answers_whether_invalid:
            game = Game()
            load_advent_dat(game)
            game.start()
            # This will test if argument to callback is None
            game.yesno_callback = self.assertIsNone
            # Run the actual test
            game.do_command(answer3)
Example #52
0
    def testdocommand_possibleanswers(self):
        game=Game()
        load_advent_dat(game)
        game.start()        
                
        #Listing of lists for testing
        listpositiveanswer=['y','yes']
        listnegativeanswer=['n','no']
        listerroranswer=['perhaps','si','nope','sure']

        #Testing the lists        
        for answer in listpositiveanswer:
            game.yesnocallback=self.assertTrue
            game._do_command([answer])
        
        for answer in listnegativeanswer:
            game.yesnocallback=self.assertFalse
            game._do_command([answer])
                    
        for answer in listerroranswer:
            game.yesnocallback=self.assertIsNotNone
            game._do_command([answer])                     
Example #53
0
    def test_do_command(self):
        game=Game()
        load_advent_dat(game)
        game.start()

        #test if callback is True for valid inputs of 'yes' and 'y'
        game.yesno_callback=self.assertTrue
        game.do_command(['yes'])
        game.yesno_callback=self.assertTrue
        game.do_command(['y'])	
		
        #test if callback is False for valid inputs of 'no' and 'n'
        game.yesno_callback=self.assertFalse
        game.do_command(['no'])
        game.yesno_callback=self.assertFalse
        game.do_command(['n'])

        #test if callback is None for invalid inputs
        game.yesno_callback=self.assertIsNone
        game.do_command(['bad input'])
        game.yesno_callback=self.assertIsNone
        game.do_command(['YESS'])
Example #54
0
    def test_do_command_checks_yesno_inputs_correctly(self):
        # Valid yes and no inputs, as specified in the Game class.
        VALID_YES_ANSWERS = ['y', 'yes']
        VALID_NO_ANSWERS = ['n', 'no']

        # Test a variety of possible answers that the user may input, including
        # valid yes answers, valid no answers, and invalid answers.
        possible_answers = [
            'y', 'yes', 'n', 'no', 'typo', 'sure why not', 'okay', '129jio43w2'
        ]

        for answer in possible_answers:
            # Initialize game
            game = Game()
            load_advent_dat(game)
            game.start()

            isinvalidword = False  # Keeps track of whether the answer is invalid

            # The test for a valid yes answer.
            if answer in VALID_YES_ANSWERS:
                game.yesno_callback = self.assertTrue
                print "For the valid input answer '%s', TestCase assertTrue function succeeded." % answer
            # The test for a valid no answer.
            elif answer in VALID_NO_ANSWERS:
                game.yesno_callback = self.assertFalse
                print "For the valid input answer '%s', TestCase assertFalse function succeeded." % answer
            # Else the answer is invalid.
            else:
                isinvalidword = True

            game.do_command([answer])

            # The test for an invalid answer.
            if isinvalidword:
                expected_output = 'PLEASE ANSWER THE QUESTION.\n'
                self.assertEqual(game.output, expected_output)
                print "For the invalid input answer '%s', TestCase assertEqual function succeeded." % answer
Example #55
0
    def test_do_commands(self):
        game = Game()
        load_advent_dat(game)
        game.start()

        #Test how 'y' answer is handled
        game.yesno_callback = self.assertTrue
        game.do_command(['y'])

        #Test how 'yes' answer is handled
        game.yesno_callback = self.assertTrue
        game.do_command(['yes'])

        #Test how 'n' answer is handled
        game.yesno_callback = self.assertFalse
        game.do_command(['n'])

        #Test how 'no' answer is handled
        game.yesno_callback = self.assertFalse
        game.do_command(['no'])

        #Test how an answer not in YESNO_ANSWERS dictionary like 'xyz' is handled
        game.yesno_callback = self.assertIsNone
        game.do_command(['xyz'])
Example #56
0
 def setUp(self):
     game = Game()
     load_advent_dat(game)
     self.words = set(w.synonyms[0].text for w in game.vocabulary.values())
     self.words.remove('suspend')
Example #57
0
 def test_do_commands_with_answer_invalid(self):
     game = Game()
     load_advent_dat(game)
     game.start()
     self.assertTrue(game.yesno_callback, None)
     game.do_command(['invalid'])