Esempio n. 1
0
    def test_combat_round_riposte(self, mock_output, mock_choice, mock_roll):
        test_p1 = {
            'Name': 'Batman',
            'Class': 'fighter',
            'Dexterity': 5,
            'HP': {
                'Current': 10,
                'Max': 10
            },
            'Attacks':
            ['a batarang!', 'his skill, cunning and fighting prowess!']
        }
        test_p2 = {
            'Name': 'Superman',
            'Class': 'warlock',
            'Dexterity': 4,
            'HP': {
                'Current': 5,
                'Max': 5
            },
            'Attacks': ['What does he really have besides his fists?']
        }

        dungeonsanddragons.combat_round(test_p1, test_p2)

        expected_output = ["Zounds! 2 damage done!\n", "Wow! 3 damage done!\n"]
        for output in expected_output:
            self.assertIn(output, mock_output.getvalue())
    def test_combat_round2(self, mock_stdout, mock_first, mock_roll,
                           mock_damage):
        # Tests case where opponent_one goes first and opponent_two dies
        attacker_winner = {
            'Name': 'Legoxo',
            'Class': 'blood hunter',
            'Health': 1,
            'Strength': 4,
            'Dexterity': 2,
            'Constitution': 9,
            'Intelligence': 13,
            'Wisdom': 11,
            'Charisma': 10,
            'XP': 0,
            'Inventory': []
        }

        opponent_loser = {
            'Name': 'Pikachu',
            'Class': 'blood hunter',
            'Health': 2,
            'Strength': 4,
            'Dexterity': 2,
            'Constitution': 9,
            'Intelligence': 13,
            'Wisdom': 11,
            'Charisma': 10,
            'XP': 0,
            'Inventory': []
        }
        expected_output = 'Legoxo rolled a 13 , Pikachu has a dexterity of 2' + '\n' \
                          + 'Attack of 4 was successfully struck' + '\n' + 'Pikachu has died' + '\n'

        dungeonsanddragons.combat_round(attacker_winner, opponent_loser)
        self.assertEqual(mock_stdout.getvalue(), expected_output)
Esempio n. 3
0
    def test_combat_round_initiator_misses(self, mock_output, mock_choice,
                                           mock_roll):
        test_p1 = {
            'Name': 'Batman',
            'Class': 'fighter',
            'Dexterity': 5,
            'HP': {
                'Current': 10,
                'Max': 10
            },
            'Attacks':
            ['a batarang!', 'his skill, cunning and fighting prowess!']
        }
        test_p2 = {
            'Name': 'Superman',
            'Class': 'warlock',
            'Dexterity': 4,
            'HP': {
                'Current': 5,
                'Max': 5
            },
            'Attacks': ['What does he really have besides his fists?']
        }

        dungeonsanddragons.combat_round(test_p1, test_p2)

        self.assertIn("A miss!\n", mock_output.getvalue())
    def test_combat_round_dice_1_same_as_dice_2(self, mock_stdout):
        """Test combat_round function when opponent 1's roll number is same as opponent 2's.

        The result is expected to print out same as expected_output
        """
        with patch('random.randint', side_effect=[1, 1, 2, 1, 14, 9]):
            dungeonsanddragons.combat_round(self.opponent_one,
                                            self.opponent_two)
            expected_output = "Same number, Roll again!\n"\
                              "---------- Combat 1 ----------\n" \
                              "codeky rolled 14\n" \
                              "riqozi's dex : 13\n" \
                              "codeky damaged 9 to riqozi\n" \
                              "riqozi has died..\n"
            self.assertEqual(mock_stdout.getvalue(), expected_output)
    def test_combat_round_dice_1_less_than_dice_2_and_is_dead_true(
            self, mock_stdout):
        """Test combat_round function when opponent 1's roll number is less than opponent 2's,
        and the opponent 1 is dead after being attacked.

        The result is expected to print out same as expected_output
        """
        with patch('random.randint', side_effect=[1, 2, 12, 10]):
            dungeonsanddragons.combat_round(self.opponent_one,
                                            self.opponent_two)
            expected_output = "---------- Combat 1 ----------\n"\
                              "riqozi rolled 12\n"\
                              "codeky's dex : 6\n"\
                              "riqozi damaged 10 to codeky\n"\
                              "codeky has died..\n"
            self.assertEqual(mock_stdout.getvalue(), expected_output)
    def test_combat_round_dice_1_greater_than_dice_2_and_is_dead_true(
            self, mock_stdout):
        """Test combat_round function when opponent 1's roll number is greater than opponent 2's,
        and the opponent 2 is dead after being attacked.

        The result is expected to print out same as expected_output
        """
        with patch('random.randint', side_effect=[2, 1, 14, 9]):
            dungeonsanddragons.combat_round(self.opponent_one,
                                            self.opponent_two)
            expected_output = "---------- Combat 1 ----------\n"\
                              "codeky rolled 14\n"\
                              "riqozi's dex : 13\n"\
                              "codeky damaged 9 to riqozi\n"\
                              "riqozi has died..\n"
            self.assertEqual(mock_stdout.getvalue(), expected_output)
    def test_combat_round5(self, mock_stdout, mock_first, mock_roll,
                           mock_damage):
        # Tests case where opponent_one and opponent_two survive the fight
        attacker_survive = {
            'Name': 'Legoxo',
            'Class': 'blood hunter',
            'Health': 10,
            'Strength': 4,
            'Dexterity': 20,
            'Constitution': 9,
            'Intelligence': 13,
            'Wisdom': 11,
            'Charisma': 10,
            'XP': 0,
            'Inventory': []
        }

        opponent_survive = {
            'Name': 'Pikachu',
            'Class': 'blood hunter',
            'Health': 20,
            'Strength': 4,
            'Dexterity': 2,
            'Constitution': 9,
            'Intelligence': 13,
            'Wisdom': 11,
            'Charisma': 10,
            'XP': 0,
            'Inventory': []
        }
        expected_output = 'Pikachu rolled a 3 , Legoxo has a dexterity of 20' + '\n' \
                          + 'Attack did not strike and now Legoxo gets a chance to attack' + '\n' \
                          + 'Legoxo rolled a 3 , Pikachu has a dexterity of 2' + '\n' \
                          + 'Attack of 3 was successfully struck' + '\n' + \
                          'Both combatants survived the fight. Legoxo now' +\
                          ' has a health of 10 and Pikachu now has a health of  17' + '\n'
        dungeonsanddragons.combat_round(attacker_survive, opponent_survive)
        self.assertEqual(mock_stdout.getvalue(), expected_output)
 def test_combat_round8(self):
     # Tests that opponent_one and opponent_two must be dictionaries and not float type
     with self.assertRaises(TypeError):
         dungeonsanddragons.combat_round(2.5, 6.7)
 def test_combat_round7(self):
     # Tests that opponent_one and opponent_two must be dictionaries and not integer type
     with self.assertRaises(TypeError):
         dungeonsanddragons.combat_round(1, 2)