Example #1
0
    def test_monster_hit_user_ten_percent_print_output_dead(self, mock_stdout):
        """Test monster_hit_user_ten_percent if it prints valid output when user died.

        The result is expected True
        """
        seed(2)  # damage = 1 , first_num, second_num = 2
        expected_output = "Monster damaged 1 to you. You died.\n"
        monster.monster_hit_user_ten_percent(self.test_user)  # hp = 1
        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()
Example #3
0
    def test_monster_hit_user_ten_percent_return_true(self):
        """Test monster_hit_user_ten_percent when returns True.
        Because ten_percent_chance (support function) returns True

        The result is expected True
        """
        seed(2)  # damage = 1 , first_num, second_num = 2
        my_bool = monster.monster_hit_user_ten_percent(self.test_user)
        self.assertEqual(True, my_bool)
Example #4
0
    def test_monster_hit_user_ten_percent_return_false(self):
        """Test monster_hit_user_ten_percent when returns False.
        Because ten_percent_chance (support function) returns False

        The result is expected True
        """
        seed(0)  # damage = 4, first_num = 7, second_num = 1
        my_bool = monster.monster_hit_user_ten_percent(self.test_user)
        self.assertEqual(False, my_bool)