def test_hero_multi_weapon_attack(): strength = superheroes.Weapon("Overwhelming Strength", 200) sword_of_truth = superheroes.Weapon("Sword of Truth", 700) Athena = superheroes.Hero("Athena") Athena.add_ability(strength) Athena.add_ability(sword_of_truth) assert len(Athena.abilities) == 2 test_runs = 100 for _ in range(0, test_runs): attack = Athena.attack() assert attack <= 900 and attack >= 0
def test_hero_weapon_attack_mean_value(): kkrunch = superheroes.Hero("Kaptain Krunch") strength = random.randint(10, 30000) min_attack = strength // 2 big_strength = superheroes.Weapon("Sword of Whimsy", strength) kkrunch.add_ability(big_strength) calculated_mean = (strength - min_attack) // 2 + min_attack accepted_window = 400 iterations = 6000 sum_of_sqr = 0 total_attack = 0 for _ in range(iterations): attack_value = kkrunch.attack() assert attack_value >= min_attack 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 - accepted_window, actual_mean + accepted_window)) print("Tested Result: {}".format(actual_mean)) assert actual_mean <= calculated_mean + accepted_window assert actual_mean >= calculated_mean - accepted_window
def test_hero_weapon_equip(): sans = superheroes.Hero("Comic Sans") weapon = superheroes.Weapon("Garlic Hot Sauce", 400) sans.add_ability(weapon) assert len(sans.abilities) == 1 assert sans.abilities[0].name == "Garlic Hot Sauce" assert sans.name == "Comic Sans"
def test_hero_attack(): flash = superheroes.Hero("The Flash") assert flash.attack() == 0 pesto = superheroes.Weapon("Pesto Sauce", 8000) flash.add_ability(pesto) attack = flash.attack() assert attack <= 8000 and attack >= 4000
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_weapon(): weapons = [ "Antimatter Gun", "Star Cannon", "Black Hole Ram Jet", "Laser Sword", "Laser Cannon", "Ion Accellerated Disc Drive", "Superhuman Strength", "Blinding Lights", "Ferociousness", "Speed of Hermes", "Lightning Bolts" ] name = weapons[random.randint(0, len(weapons) - 1)] power = random.randint(27, 700000) return superheroes.Weapon(name, power)
def test_team_attack_draw_weapons(): team_one = superheroes.Team("One") tony = superheroes.Hero("Iron Man") blasters = superheroes.Weapon("Blasters", 1000000) suit = superheroes.Armor("armored suit", 1) tony.add_weapon(blasters) tony.add_armor(suit) team_one.add_hero(tony) team_two = superheroes.Team("Two") steve = superheroes.Hero("Captain America") kick = superheroes.Weapon("Kick", 1000000) shield = superheroes.Armor("Shield", 1) steve.add_weapon(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_hero_attack_standard_deviation(): willow_waffle = superheroes.Hero("Willow Waffle") strength = random.randint(400, 30000) travel_agent = superheroes.Weapon("Travel Agents", strength) willow_waffle.add_ability(travel_agent) 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("Random values not given. Please make sure you're not returning the same value every time.") assert standard_dev != 0.0
def test_hero_attack_standard_deviation(): willow_waffle = superheroes.Hero("Willow Waffle") strength = random.randint(400, 30000) travel_agent = superheroes.Weapon("Travel Agents", strength) willow_waffle.add_ability(travel_agent) 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_weapon_attack(): big_stick = superheroes.Weapon("Overwhelming Stick", 200) test_runs = 100 for _ in range(0, test_runs): attack = big_stick.attack() assert attack <= 200 and attack >= 100
def test_weapon_instance(): big_stick = superheroes.Weapon("Overwhelming Stick", 200) assert "Weapon" in str(big_stick)
def test_weapon_attack(): batmanAbility = superheroes.Weapon("Detective", 2) damage = batmanAbility.attack() assert (damage > 0 and damage < 3)