def test_attack_hit_opponent_two_dies(self, mock_roll_die, mock_stdout): bad_fighter = { "Name": "Monoza", "Class": "sorcerer", "HP": 6, "Strength": 12, "Dexterity": 12, "Constitution": 3, "Intelligence": 9, "Wisdom": 9, "Charisma": 18, "XP": 0, "Inventory": ["The Elder Wand"] } good_fighter = { "Name": "Bagiko", "Class": "bard", "HP": 4, "Strength": 12, "Dexterity": 18, "Constitution": 15, "Intelligence": 9, "Wisdom": 6, "Charisma": 9, "XP": 0, "Inventory": ["The Unicorn Horn", "The Belmont Whip"] } expected_output = "Bagiko goes first:\n" \ "Bagiko strikes!\n"\ "Monoza has taken a 6 point hit!\n"\ "Monoza has perished.\n"\ "End of round --> Bagiko is the winner!\n" dungeonsanddragons.combat_round(good_fighter, bad_fighter) self.assertEqual(mock_stdout.getvalue(), expected_output)
def test_tie_roll(self, mock_roll_die, mock_attack, mock_stdout): attacker = { 'Name': 'Attacker', 'Race': 'dwarf', 'Class': 'bard', 'HP': [7, 7], 'Strength': 14, 'Dexterity': 9, 'Constitution': 6, 'Intelligence': 11, 'Wisdom': 13, 'Charisma': 9, 'XP': 0, 'Inventory': [] } defender = { 'Name': 'Defender', 'Race': 'dwarf', 'Class': 'bard', 'HP': [7, 7], 'Strength': 14, 'Dexterity': 1, 'Constitution': 6, 'Intelligence': 11, 'Wisdom': 13, 'Charisma': 9, 'XP': 0, 'Inventory': [] } expected_output = 'Rolling to determine attack priority...\nAttacker rolled: 5\n' \ 'Defender rolled: 5\nA tie! Rolling again...\nAttacker rolled: 9\n' \ 'Defender rolled: 1\nAttacker attacks first!\n' combat_round(attacker, defender) self.assertEqual(mock_stdout.getvalue(), expected_output)
def test_hp_reduction(self, mock_generate_name, mock_roll_die, mock_input): expected_output = '' character_1 = dungeonsanddragons.create_character(5) character_2 = dungeonsanddragons.create_character(5) dungeonsanddragons.combat_round(character_1, character_2) character_1_hp = character_1['HitPoints'] == 4 character_2_hp = character_2['HitPoints'] == 3 self.assertTrue(character_1_hp and character_2_hp)
def test_combat_round_hit_hit(self, mock_roll, mock_output): player_1 = { "Name": "Ophelia", "Class": "monk", "Race": "elf", "HP": [8, 8], "Strength": 3, "Dexterity": 3, "Constitution": 3, "Intelligence": 3, "Wisdom": 3, "Charisma": 3, "XP": 0, "Inventory": ["Boots of Swiftness", "Boots of Alacrity"] } player_2 = { "Name": "Peachy", "Class": "monk", "Race": "elf", "HP": [8, 6], "Strength": 3, "Dexterity": 3, "Constitution": 3, "Intelligence": 3, "Wisdom": 3, "Charisma": 3, "XP": 0, "Inventory": ["Boots of Swiftness", "Boots of Alacrity"] } expected = """ Ophelia will go first. Peachy's HP: 6/8 The attack was a success! Peachy took 1 damage. Peachy's HP: 5/8 Ophelia's HP: 8/8 The attack was a success! Ophelia took 1 damage. Ophelia's HP: 7/8 """ combat_round(player_1, player_2) self.assertEqual(expected, mock_output.getvalue())
def test_attack_hit_hit_both_survive(self, mock_roll_die, mock_stdout): mediocre_fighter_2 = { "Name": "Monoza", "Class": "sorcerer", "HP": 6, "Strength": 12, "Dexterity": 12, "Constitution": 3, "Intelligence": 9, "Wisdom": 9, "Charisma": 18, "XP": 0, "Inventory": ["The Elder Wand"] } mediocre_fighter = { "Name": "Bagiko", "Class": "bard", "HP": 4, "Strength": 12, "Dexterity": 18, "Constitution": 15, "Intelligence": 9, "Wisdom": 6, "Charisma": 9, "XP": 0, "Inventory": ["The Unicorn Horn", "The Belmont Whip"] } expected_output = "Bagiko goes first:\n" \ "Bagiko strikes!\n"\ "Monoza has taken a 3 point hit!\n"\ "Monoza's HP has dropped to 3.\n"\ "Monoza's turn:\n"\ "Monoza strikes!\n"\ "Bagiko has taken a 2 point hit!\n"\ "Bagiko's HP has dropped to 2.\n"\ "End of round --> Bagiko's HP is 2. Monoza's HP is 3.\n" dungeonsanddragons.combat_round(mediocre_fighter, mediocre_fighter_2) self.assertEqual(mock_stdout.getvalue(), expected_output)
def test_attack_miss_miss_both_survive(self, mock_roll_die, mock_stdout): bad_fighter = { "Name": "Monoza", "Class": "sorcerer", "HP": 1, "Strength": 12, "Dexterity": 12, "Constitution": 3, "Intelligence": 9, "Wisdom": 9, "Charisma": 18, "XP": 0, "Inventory": ["The Elder Wand"] } bad_fighter_2 = { "Name": "Bagiko", "Class": "bard", "HP": 4, "Strength": 12, "Dexterity": 18, "Constitution": 15, "Intelligence": 9, "Wisdom": 6, "Charisma": 9, "XP": 0, "Inventory": ["The Unicorn Horn", "The Belmont Whip"] } expected_output = "Monoza goes first:\n" \ "Monoza strikes!\n"\ "Monoza missed!\n"\ "Bagiko's turn:\n"\ "Bagiko strikes!\n"\ "Bagiko missed!\n"\ "End of round --> Monoza's HP is 1. Bagiko's HP is 4.\n" dungeonsanddragons.combat_round(bad_fighter, bad_fighter_2) self.assertEqual(mock_stdout.getvalue(), expected_output)
def test_combat_round_stop_mid_round(self, mock_input): combat_round(opponent_1, opponent_2) self.assertTrue(opponent_1["HP"] == 10 and opponent_2["HP"] == 0)
def test_combat_round_opponent_2_dies(self, mock_input): combat_round(opponent_1, opponent_2) self.assertEqual(opponent_2["HP"], 0)
def test_incorrect_character_input(self): with self.assertRaises(TypeError): dungeonsanddragons.combat_round(5, 3)