def test_generate_monster_print_output(self, mock_stdout):
        """Test encounter_monster if it prints valid output.

        The result is expected True
        """
        expected_output = "** Monster generated **\n"
        monster.generate_monster()
        self.assertEqual(mock_stdout.getvalue(), expected_output)
def fight_or_run_away(user: dict) -> None:
    """Determine if user runs away of fights based on user's input.

    If user choose runaway, invoke monster_hit_user_ten_percent() to determine if the monster hits the user by 10 %
    chance, and then print helpful message.
    If user choose fight, invoke combat().
    If user's input is invalid, invoke not_understand_command() to print helpful message and get user's input again.
    PARAM: user, a dictionary
    PRECONDITION: user, must be a dictionary has valid keys and values
    POSTCONDITION: Print helpful message when user runs away
    """
    ran_or_dead = False
    mob = monster.generate_monster()
    while not ran_or_dead:
        user_choice = input(
            "Do you want to fight or runaway? (F/R) ").strip().lower()
        if user_choice in ['f', 'r', 'fight', 'runaway', 'run']:
            if run_away(
                    user_choice) is True:  # check if user wants to run away
                if not monster.monster_hit_user_ten_percent(user):
                    print("** You ran away successfully! **")
            else:
                initiate_combat(user, mob)
            ran_or_dead = True
        else:
            support_function.not_understand_command()
    def test_generate_monster_length_of_return(self):
        """Test encounter_monster if the length of return is valid.

        The result is expected True
        """
        test_monster = monster.generate_monster()
        self.assertEqual(2, len(test_monster))
    def test_generate_monster_type_of_return(self):
        """Test encounter_monster if the type of return is valid.

        The result is expected True
        """
        test_monster = monster.generate_monster()
        self.assertEqual(dict, type(test_monster))
Ejemplo n.º 5
0
 def test_generate_monster5(self, mock_class, mock_dexterity, mock_damage):
     self.assertEqual(
         {
             'Name': 'Pax',
             'Health': 5,
             'Damage': 2,
             'Dexterity': 3
         }, monster.generate_monster())
Ejemplo n.º 6
0
 def test_generate_monster6(
         self):  # Tests that return value is a dictionary
     self.assertEqual(dict, type(monster.generate_monster()))