def test_hero_defend_multi_armor(): jodie = superduel.Hero("Jodie Foster") gauntlets = superduel.Armor("Gauntlets", 4000) science = superduel.Armor("Science", 9000) jodie.add_armor(gauntlets) jodie.add_armor(science) defend = jodie.defend() assert defend <= 13000 and defend >= 0
def test_hero_defense_mean_value(): athena = superduel.Hero("Athena") strength = random.randint(400, 30000) big_strength = superduel.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 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 superduel.Armor(name, power)
def test_team_attack_deaths(): team_one = superduel.Team("One") jodie = superduel.Hero("Jodie Foster") aliens = superduel.Ability("Alien Friends", 10000) jodie.add_ability(aliens) team_one.add_hero(jodie) team_two = superduel.Team("Two") athena = superduel.Hero("Athena") socks = superduel.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_hero_defense_standard_deviation(): willow_waffle = superduel.Hero("Willow Waffle") strength = random.randint(400, 30000) willow = superduel.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 # Get Square Deviations 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_hero_equip_armor(): jodie = superduel.Hero("Jodie Foster") gauntlets = superduel.Armor("Gauntlets", 30) jodie.add_armor(gauntlets) assert len(jodie.armor) == 1 assert jodie.armor[0].name == "Gauntlets"
def test_dead_hero_defense(): hero = superduel.Hero("Vlaad", 0) garlic = superduel.Armor("Garlic", 30000) hero.add_armor(garlic) assert hero.defend() == 0
def test_hero_defense(): jodie = superduel.Hero("Jodie Foster") gauntlets = superduel.Armor("Gauntlets", 30) jodie.add_armor(gauntlets) defense = jodie.defend() assert defense >= 0 and defense <= 30