def test_hero_defend_multi_armor(): jodie = superheroes.Hero("Jodie Foster") gauntlets = superheroes.Armor("Gauntlets", 4000) science = superheroes.Armor("Science", 9000) jodie.add_armor(gauntlets) jodie.add_armor(science) defend = jodie.defend() assert defend <= 13000 and defend >= 0
def test_hero_defense(): jodie = superheroes.Hero("Jodie Foster") gauntlets = superheroes.Armor("Gauntlets", 30) jodie.add_armor(gauntlets) defense = jodie.defend() assert defense >= 0 and defense <= 30 print('pass test hero def')
def test_armor(): armor = superheroes.Armor("The Ring", 200) for _ in range(0, 500): # defense = armor.block() defense = armor.block() print(defense) assert (defense <= 200 and defense >= 0)
def test_hero_defense_mean_value(): athena = superheroes.Hero("Athena") strength = random.randint(400, 30000) big_strength = superheroes.Armor("Overwhelming Shield", strength) athena.add_armor(big_strength) calculated_mean = strength // 2 iterations = 8000 total_attack = 0 accepted_window = 400 for _ in range(iterations): attack_value = athena.defend() assert attack_value >= 0 and attack_value <= strength total_attack += attack_value actual_mean = total_attack / iterations print("Max Allowed: {}".format(strength)) print("Defenses Tested: {}".format(iterations)) print("Mean -- calculated: {} | actual: {}".format(calculated_mean, actual_mean)) print( "Acceptable deviation from mean: {} | Current deviation from mean: {}". format(accepted_window, abs(calculated_mean - actual_mean))) print("Acceptable Min: {} | Acceptable Max: {}".format( actual_mean - accepted_window, actual_mean + accepted_window)) assert actual_mean <= calculated_mean + \ accepted_window and actual_mean >= calculated_mean - accepted_window
def test_str_to_obj(): # make a Hero and equip with an Armor avenger = superheroes.Hero("Iron Man") armor = superheroes.Armor("Hulkbuster Suit", 900000) avenger.add_armor(armor) result = avenger.str_to_object("Hulkbuster Suit", "Armor") # print(type(result)) assert type(result) == type(armor), "Incorrect object type returned."
def test_capture_index(): # make a Hero and equip with an Armor avenger = superheroes.Hero("Iron Man") armor = superheroes.Armor("Hulkbuster Suit", 900000) avenger.add_armor(armor) # look for armor in self.armors, check index return value return_index = avenger.capture_index("Hulkbuster Suit", "Armor") assert return_index == 0, "Incorrect index value returned."
def create_armor(): armors = [ "Calculator", "Laser Shield", "Invisibility", "SFPD Strike Force", "Social Workers", "Face Paint", "Damaskus Shield", "Bamboo Wall", "Forced Projection", "Thick Fog", "Wall of Will", "Wall of Walls", "Obamacare", "Thick Goo" ] name = armors[random.randint(0, len(armors) - 1)] power = random.randint(23, 700000) return superheroes.Armor(name, power)
def test_team_attack_draw_abilities(): team_one = superheroes.Team("One") tony = superheroes.Hero("Iron Man") blasters = superheroes.Ability("Blasters", 1000000) suit = superheroes.Armor("armored suit", 1) tony.add_ability(blasters) tony.add_armor(suit) team_one.add_hero(tony) team_two = superheroes.Team("Two") steve = superheroes.Hero("Captain America") kick = superheroes.Ability("Kick", 1000000) shield = superheroes.Armor("Shield", 1) steve.add_ability(kick) steve.add_armor(shield) team_two.add_hero(steve) assert team_one.heroes[0].current_health == 100 assert team_two.heroes[0].current_health == 100 team_one.attack(team_two) assert team_one.heroes[0].current_health <= 0 assert team_two.heroes[0].current_health <= 0
def test_team_attack_knock_each_other_out(): team_one = superheroes.Team("One") tony = superheroes.Hero("Iron Man") blasters = superheroes.Ability("Blasters", 10000) suit = superheroes.Armor("armored suit", 1) tony.add_ability(blasters) tony.add_armor(suit) team_one.add_hero(tony) team_two = superheroes.Team("Two") steve = superheroes.Hero("Captain America") kick = superheroes.Ability("Kick", 10000) shield = superheroes.Armor("Shield", 1) steve.add_ability(kick) steve.add_armor(shield) team_two.add_hero(steve) assert team_one.heroes[0].deaths == 0 assert team_two.heroes[0].deaths == 0 team_one.attack(team_two) assert team_one.heroes[0].deaths == 1 assert team_two.heroes[0].deaths == 1
def test_team_attack_deaths(): team_one = superheroes.Team("One") jodie = superheroes.Hero("Jodie Foster") aliens = superheroes.Ability("Alien Friends", 10000) jodie.add_ability(aliens) team_one.add_hero(jodie) team_two = superheroes.Team("Two") athena = superheroes.Hero("Athena") socks = superheroes.Armor("Socks", 10) athena.add_armor(socks) team_two.add_hero(athena) assert team_two.heroes[0].deaths == 0 team_one.attack(team_two) assert team_two.heroes[0].deaths == 1
def test_team_revive_heroes(): batman = superheroes.Hero("Batman") batAttack = superheroes.Ability("batPunch", attackStrenght=100) batman.add_ability(batAttack) batsuit = superheroes.Armor("Bat Suit", 1) batman.add_armor(batsuit) superman = superheroes.Hero("Superman") justiceLeague = superheroes.Team("League") evilLeague = superheroes.Team("Evil League") justiceLeague.add_hero(batman) evilLeague.add_hero(superman) justiceLeague.attack(evilLeague) evilLeague.revive_heroes() justiceLeague.revive_heroes(300) assert superman.current_health == 100 and batman.current_health == 300
def test_team_attack_only_one_hero(): team_one = superheroes.Team("One") tony = superheroes.Hero("Iron Man") blasters = superheroes.Ability("Blasters", 10000) suit = superheroes.Armor("armored suit", 1) tony.add_ability(blasters) tony.add_armor(suit) team_one.add_hero(tony) team_two = superheroes.Team("Two") assert team_one.heroes[0].current_health == 100 team_one.attack(team_two) assert team_one.heroes[0].current_health == 100
def test_team_attack(): batman = superheroes.Hero("Batman") batAttack = superheroes.Ability("batPunch", attackStrenght=100) batman.add_ability(batAttack) batsuit = superheroes.Armor("Bat Suit", 1) batman.add_armor(batsuit) superman = superheroes.Hero("Superman") justiceLeague = superheroes.Team("League") evilLeague = superheroes.Team("Evil League") justiceLeague.add_hero(batman) evilLeague.add_hero(superman) justiceLeague.attack(evilLeague) assert superman.kills == 0 and superman.deaths == 1 and batman.kills == 1 and batman.deaths == 0
def test_hero_defense_mean_value(): athena = superheroes.Hero("Athena") strength = random.randint(10, 30000) big_strength = superheroes.Armor("Overwhelming Shield", strength) athena.add_armor(big_strength) calculated_mean = strength // 2 iterations = 8000 total_attack = 0 for _ in range(iterations): attack_value = athena.defend() assert attack_value >= 0 and attack_value <= strength total_attack += attack_value actual_mean = total_attack / iterations print("Max Allowed Damage: {}".format(strength)) print("Attacks Tested: {}".format(iterations)) print("Mean -- calculated: {} | actual: {}".format(calculated_mean, actual_mean)) print("Acceptable Min: {} | Acceptable Max: {}".format(actual_mean - 150, actual_mean + 150)) assert actual_mean <= calculated_mean + 150 and actual_mean >= calculated_mean - 150
def test_hero_defense_standard_deviation(): willow_waffle = superheroes.Hero("Willow Waffle") strength = random.randint(400, 30000) willow = superheroes.Armor("Willowness", strength) willow_waffle.add_armor(willow) defenses = list() total_defend = 0 number_tests = 100 for _ in range(number_tests): defense = willow_waffle.defend() defenses.append(defense) total_defend += defense mean = total_defend / number_tests for index, value in enumerate(defenses): defenses[index] = math.pow(value - mean, 2) standard_dev = math.sqrt(sum(defenses) / len(defenses)) print("Hero Armor must block with random value.") print("Standard Deviation Cannot be 0.") assert standard_dev != 0.0
def test_armor_block(): shield = superheroes.Armor("Shield", 5) block = shield.block() assert (-1 < block < 6)
import superheroes debug_ability = superheroes.Ability("Debugging Ability", 20) assert (0 <= debug_ability.attack() <= 20), "Ability.attack() generated out of range" debug_ability_1 = superheroes.Ability("Debugging Ability 1", 30) debug_block = superheroes.Armor("Debug block", 20) assert (0 <= debug_block.block() <= 20), "Armor.block() generated out of range" debug_block_1 = superheroes.Armor("Debug block 1", 30) test_hero = superheroes.Hero("Grace Hopper", 200) test_hero_1 = superheroes.Hero("John Stickler", 150) test_hero.add_ability(debug_ability) test_hero.add_armor(debug_block) test_hero_1.add_ability(debug_ability_1) test_hero_1.add_armor(debug_block_1) test_hero.fight(test_hero_1)
def test_hero_equip_armor(): jodie = superheroes.Hero("Jodie Foster") gauntlets = superheroes.Armor("Gauntlets", 30) jodie.add_armor(gauntlets) assert len(jodie.armors) == 1 assert jodie.armors[0].name == "Gauntlets"
def test_dead_hero_defense(): hero = superheroes.Hero("Vlaad", 0) garlic = superheroes.Armor("Garlic", 30000) hero.add_ability(garlic) assert hero.defend() == 0
def test_hero_add_armor(): batman = superheroes.Hero("Batman") batsuit = superheroes.Armor("Bat Suit", 1) batman.add_armor(batsuit) defence = batman.defence assert (defence > -1 and defence < 2)
def test_hero_take_damage_with_armor(): batman = superheroes.Hero("Batman") batsuit = superheroes.Armor("Bat Suit", 1) batman.add_armor(batsuit) batman.take_damage(50) assert (batman.current_health == 51 or batman.current_health == 50)