def test_hero_add_multi_ability(): big_strength = superheroes.Ability("Overwhelming Strength", 300) speed = superheroes.Ability("Lightning Speed", 500) Athena = superheroes.Hero("Athena") assert len(Athena.abilities) == 0 Athena.add_ability(big_strength) assert len(Athena.abilities) == 1 Athena.add_ability(speed) assert len(Athena.abilities) == 2 assert "Ability" in str(Athena.abilities[0]) assert Athena.abilities[0].name == "Overwhelming Strength"
def test_hero_fight(): batman = superheroes.Hero("Batman") batmanAbility = superheroes.Ability("Detective", 100) batman.add_ability(batmanAbility) superman = superheroes.Hero("Superman") batman.fight(superman) catwoman = superheroes.Hero("Cat Woman") captainmarvel = superheroes.Hero("Captain Marvel") catwomanAbility = superheroes.Ability("Meow", 100) catwoman.add_ability(catwomanAbility) captainmarvel.fight(catwoman) assert (superman.is_alive() == False and captainmarvel.is_alive() == False)
def test_hero_ability_attack_mean_value(): athena = superheroes.Hero("Athena") strength = random.randint(10, 30000) big_strength = superheroes.Ability("Overwhelming Strength", strength) athena.add_ability(big_strength) calculated_mean = strength // 2 iterations = 6000 accepted_window = 400 total_attack = 0 for _ in range(iterations): attack_value = athena.attack() 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 Distance from Mean: {} | Average distance from mean: {}". format(accepted_window, abs(calculated_mean - actual_mean))) print("Acceptable min attack: {} | Acceptable max attack: {}".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_hero_attack(): flash = superheroes.Hero("The Flash") assert flash.attack()[0] == 0 pesto = superheroes.Ability("Pesto Sauce", 8000) flash.add_ability(pesto) attack = flash.attack()[1] assert attack <= 8000 and attack >= 4000
def test_hero_ability_attack_mean_value(): athena = superheroes.Hero("Athena") strength = random.randint(10, 30000) big_strength = superheroes.Ability("Overwhelming Strength", strength) athena.add_ability(big_strength) calculated_mean = strength // 2 iterations = 6000 sum_of_sqr = 0 total_attack = 0 for _ in range(iterations): attack_value = athena.attack() assert attack_value >= 0 and attack_value <= strength total_attack += attack_value deviation = attack_value - calculated_mean sum_of_sqr += deviation * deviation 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)) print("Tested Result: {}".format(actual_mean)) assert actual_mean <= calculated_mean + 150 and actual_mean >= calculated_mean - 150
def test_hero_attack_ability(): big_strength = superheroes.Ability("Overwhelming Strength", 30000) athena = superheroes.Hero("Athena") assert athena.attack() == 0 athena.add_ability(big_strength) attack = athena.attack() assert attack <= 30000 and attack >= 0
def test_ability_attack(): # Test for correct attack value test_runs = 400 big_strength = superheroes.Ability("Overwhelming Strength", 400) for _ in range(0, test_runs): attack = big_strength.attack() assert attack >= 0 and attack <= 400
def test_hero_kills_and_deaths(): batman = superheroes.Hero("Batman") batmanAbility = superheroes.Ability("Detective", 100) batman.add_ability(batmanAbility) superman = superheroes.Hero("Superman") batman.fight(superman) assert (batman.kills == 1 and batman.deaths == 0) and (superman.kills == 0 and superman.deaths == 1)
def test_ability_update_attack(): big_strength = superheroes.Ability("Overwhelming Strength", 300) big_strength.update_attack(400) test_runs = 100 attack = 0 for _ in range(0, test_runs): attack += big_strength.attack() assert attack <= (400 * test_runs) and attack >= (200 * test_runs)
def test_hero_add_ability(): big_strength = superheroes.Ability("Overwhelming Strength", 300) Athena = superheroes.Hero("Athena") assert len(Athena.abilities) == 0 Athena.add_ability(big_strength) assert len(Athena.abilities) == 1 assert "Ability" in str(Athena.abilities[0]) assert Athena.abilities[0].name == "Overwhelming Strength"
def test_hero_attack_weapon(): big_strength = superheroes.Ability("Overwhelming Strength", 200) Athena = superheroes.Hero("Athena") Athena.add_ability(big_strength) test_runs = 100 for _ in range(0, test_runs): attack = big_strength.attack() assert attack <= 200 and attack >= 0
def test_hero_weapon_ability_attack(): quickness = superheroes.Ability("Quickness", 1300) sword_of_truth = superheroes.Weapon("Sword of Truth", 700) Athena = superheroes.Hero("Athena") Athena.add_ability(quickness) Athena.add_ability(sword_of_truth) assert len(Athena.abilities) == 2 attack_avg(Athena, 0, 2000)
def create_ability(): abilities = [ "Alien Attack", "Science", "Star Power", "Immortality", "Grandmas Cookies", "Blinding Strength", "Cute Kittens", "Team Morale", "Luck", "Obsequious Destruction", "The Kraken", "The Fire of A Million Suns", "Team Spirit", "Canada" ] name = abilities[random.randint(0, len(abilities) - 1)] power = random.randint(45, 700000) return superheroes.Ability(name, power)
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_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_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_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_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(): 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_ability_attack_standard_deviation(): willow_waffle = superheroes.Hero("Willow Waffle") strength = random.randint(400, 30000) willow = superheroes.Ability("Willowness", strength) willow_waffle.add_ability(willow) attacks = list() total_attack = 0 number_tests = 1000 for _ in range(number_tests): cur_attack = willow_waffle.attack() attacks.append(cur_attack) total_attack += cur_attack mean = total_attack / number_tests # Get Square Deviations for index, value in enumerate(attacks): attacks[index] = math.pow(value - mean, 2) standard_dev = math.sqrt(sum(attacks) / len(attacks)) print("Standard Deviation Cannot be 0.\nRandom Numbers not generated for attack.") assert standard_dev != 0.0
def test_hero_attack_standard_deviation(): willow_waffle = superheroes.Hero("Willow Waffle") strength = random.randint(400, 30000) willow_waffle.add_ability(superheroes.Ability('arf', 100)) attacks = list() total_attack = 0 number_tests = 1000 for _ in range(number_tests): cur_attack = willow_waffle.attack_value() attacks.append(cur_attack) total_attack += cur_attack mean = total_attack / number_tests # Get Square Deviations for index, value in enumerate(attacks): attacks[index] = math.pow(value - mean, 2) standard_dev = math.sqrt(sum(attacks) / len(attacks)) print("Random values not given. Please make sure you're not returning the same value every time.") assert standard_dev != 0.0
def test_ability_name(): # Test for Correct Name big_strength = superheroes.Ability("Overwhelming Strength", 300) assert big_strength.name == "Overwhelming Strength"
# my-superheroes.py import superheroes from superheroes import Ability BobaMax = superheroes.Ability("BobaMax", 9001) print(BobaMax.name) print(BobaMax.attack())
def test_ability_instance(): big_strength = superheroes.Ability("Overwhelming Strength", 300) assert big_strength
def test_ability_instance(): # Test instantiation without error big_strength = superheroes.Ability("Overwhelming Strength", 300) assert big_strength
def test_hero_add_ability(): batman = superheroes.Hero("Batman") batmanAbility = superheroes.Ability("Detective", 10) batman.add_ability(batmanAbility) damage = batman.attack() assert (damage > -1 and damage < 11)
def test_ability_attack(): batmanAbility = superheroes.Ability("Detective", 100) damage = batmanAbility.attack() assert (damage > -1 and damage < 101)
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)