def test_combat_round_attacker_kills_defender_exactly(self, mock_roll_die): expected_values = [10, 0] # [player_health, monster_health] player = {"Name": "Vlad", "Health": 10} monster = {"Name": "Orc", "Health": 5} combat.combat_round(player, monster) self.assertEqual([player["Health"], monster["Health"]], expected_values)
def test_combat_round_global(self): """Assert that character HP is updated in global variable.""" random.seed(32) opponent = {"Name": "Dratini", "Class": "Dragon", "Attack": "Fly", "HP": 5} combat_round(opponent) self.assertEqual(pokemon, {'Name': 'Richard', 'Class': 'Bulbasaur', 'Position': [0, 2], 'HP': 5}) random.seed()
def test_combat_round_exit(self): """Assert that SystemExit is called when user has 0 HP.""" opponent = {"Name": "Mew", "Class": "Psychic", "Attack": "Hypnosis", "HP": 5} random.seed(1) with self.assertRaises(SystemExit): combat_round(opponent) random.seed()
def test_combat_round_type(self, mock_stdout): """Assert print output type.""" random.seed(0) opponent = {"Name": "Charizard", "Class": "Fire", "Attack": "Tackle", "HP": 5} combat_round(opponent) self.assertEqual(type(mock_stdout.getvalue()), str) random.seed()
def test_combat_round_player_attacks_doesnt_kill_and_overkilled( self, mock_roll_die): expected_values = [0, 1] # [player_health, monster_health] player = {"Name": "Vlad", "Health": 10} monster = {"Name": "Orc", "Health": 5} combat.combat_round(player, monster) self.assertEqual([player["Health"], monster["Health"]], expected_values)
def test_combat_round_output(self, mock_stdout): """Assert expected print output of function after execution.""" random.seed(6) expected_output = "You attacked Pikachu with a slap and he took 5 damage.\n" \ "Success! Your opponent has fainted and you gained 20 prize dollars from your battle.\n\n" opponent = {"Name": "Pikachu", "Class": "Electric", "Attack": "Static", "HP": 5} combat_round(opponent) self.assertEqual(mock_stdout.getvalue(), expected_output) random.seed()
def test_combat_round_no_retaliate(self, mock_sysout, _): character = {"HP": [10, 10], "name": "Swag"} enemy = {"HP": [4, 4], "name": "Armaan", "type": 'monster'} combat.combat_round(character, enemy) expected = """Swag sniffled in class! Swag hits Armaan where it hurts and causes them to lose 6 sanity. Armaan has finally lost it and went completely insane. """ self.assertEqual(mock_sysout.getvalue(), expected)
def test_combat_round_with_retaliate(self, mock_sysout, _): character = {"HP": [10, 10], "name": "Swag"} enemy = { "HP": [10, 10], "name": "Armaan", "type": 'monster', "attack": "Armaan says: Studies show students learn best when pushed to the edge!" } combat.combat_round(character, enemy) expected = """Swag sniffled in class! Armaan is going crazy and loses 6 sanity! Armaan says: Studies show students learn best when pushed to the edge! Swag is going crazy and loses 6 sanity! """ self.assertEqual(mock_sysout.getvalue(), expected)