示例#1
0
def test_print_heroes():
    team = superhero.Team("One")
    jodie = superhero.Hero("Jodie Foster")
    team.add_hero(jodie)
    athena = superhero.Hero("Athena")
    team.add_hero(athena)
    output_string = capture_console_output(team.view_all_heroes)

    assert "Jodie Foster" in output_string
    assert "Athena" in output_string
示例#2
0
def test_team_attack_deaths():
    team_one = superhero.Team("One")
    jodie = superhero.Hero("Jodie Foster")
    aliens = superhero.Ability("Alien Friends", 10000)
    jodie.add_ability(aliens)
    team_one.add_hero(jodie)
    team_two = superhero.Team("Two")
    athena = superhero.Hero("Athena")
    socks = superhero.Armor("Socks", 10)
    athena.add_armor(socks)
    team_two.add_hero(athena)
    assert team_two.heroes[0].deaths == 0
示例#3
0
def test_hero_weapon_attack_mean_value():
    kkrunch = superhero.Hero("Kaptain Krunch")
    strength = random.randint(10, 30000)
    min_attack = strength // 2
    big_strength = superhero.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
示例#4
0
def test_hero_ability_attack_mean_value():
    athena = superhero.Hero("Athena")
    strength = random.randint(10, 30000)
    big_strength = superhero.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_team_attack():
    team_one = superhero.Team("One")
    jodie = superhero.Hero("Jodie Foster")
    aliens = superhero.Ability("Alien Friends", 10000)
    jodie.add_ability(aliens)
    team_one.add_hero(jodie)
    team_two = superhero.Team("Two")
    athena = superhero.Hero("Athena")
    socks = superhero.Armor("Socks", 10)
    athena.add_armor(socks)
    team_two.add_hero(athena)
    assert team_two.heros[0].current_health == 100

    team_one.attack(team_two)

    assert team_two.heros[0].current_health <= 0
示例#6
0
def test_hero_defense_mean_value():
    athena = superhero.Hero("Athena")
    strength = random.randint(400, 30000)
    big_strength = superhero.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
示例#7
0
def create_hero(max_strength=100, weapons=False, armors=False, health=False):

    heroes = [
        "Athena", "Jodie Foster", "Christina Aguilera", "Gamora", "Supergirl",
        "Wonder Woman", "Batgirl", "Carmen Sandiego", "Okoye",
        "America Chavez", "Cat Woman", "White Canary", "Nakia", "Mera",
        "Iris West", "Quake", "Wasp", "Storm", "Black Widow",
        "San Luis Obispo", "Ted Kennedy", "San Francisco", "Bananas"
    ]
    name = heroes[random.randint(0, len(heroes) - 1)]
    if health:
        power = health
    else:
        power = random.randint(3, 700000)
    hero = superhero.Hero(name, power)
    if weapons and armors:
        for weapon in weapons:
            hero.add_ability(weapon)
        for armor in armors:
            hero.add_armor(armor)
    if armors and not weapons:
        for armor in armors:
            hero.add_armor(armor)

    return hero
示例#8
0
def test_team_remove_unlisted():
    # Test that if no results found return 0
    team = superhero.Team("One")
    jodie = superhero.Hero("Jodie Foster")
    team.add_hero(jodie)
    code = team.remove_hero("Athena")
    assert code == 0
示例#9
0
def test_team_remove_hero():
    team = superhero.Team("One")
    jodie = superhero.Hero("Jodie Foster")
    team.add_hero(jodie)
    assert team.heroes[0].name == "Jodie Foster"
    team.remove_hero(jodie)
    assert len(team.heroes) == 0
示例#10
0
def test_hero_attack_ability():
    big_strength = superhero.Ability("Overwhelming Strength", 30000)
    athena = superhero.Hero("Athena")
    assert athena.attack() == 0
    athena.add_ability(big_strength)
    attack = athena.attack()
    assert attack <= 30000 and attack >= 0
示例#11
0
def build_hero(num_of_weapons=0, num_of_armor=0, num_of_abilities=0):
    heroes = [
        "Athena", "Jodie Foster", "Christina Aguilera", "Gamora", "Supergirl",
        "Wonder Woman", "Batgirl", "Carmen Sandiego", "Okoye",
        "America Chavez", "Cat Woman", "White Canary", "Nakia", "Mera",
        "Iris West", "Quake", "Wasp", "Storm", "Black Widow",
        "San Luis Obispo", "Ted Kennedy", "San Francisco", "Bananas"
    ]

    weapons = []
    armors = []

    for _ in range(num_of_weapons):
        weapons.append(create_weapon())

    for _ in range(num_of_armor):
        armors.append(create_armor())

    for _ in range(num_of_abilities):
        weapons.append(create_ability())

    name = random.choice(heroes)
    hero = superhero.Hero(name)

    for item in weapons:
        hero.add_ability(item)

    for armor in armors:
        hero.add_armor(armor)

    return hero
示例#12
0
def test_hero_weapon_ability_attack():
    quickness = superhero.Ability("Quickness", 1300)
    sword_of_truth = superhero.Weapon("Sword of Truth", 700)
    Athena = superhero.Hero("Athena")
    Athena.add_ability(quickness)
    Athena.add_ability(sword_of_truth)
    assert len(Athena.abilities) == 2
    attack_avg(Athena, 0, 2000)
示例#13
0
def test_hero_defend_multi_armor():
    jodie = superhero.Hero("Jodie Foster")
    gauntlets = superhero.Armor("Gauntlets", 4000)
    science = superhero.Armor("Science", 9000)
    jodie.add_armor(gauntlets)
    jodie.add_armor(science)
    defend = jodie.defend()
    assert defend <= 13000 and defend >= 0
示例#14
0
def test_hero_attack_weapon():
    big_strength = superhero.Ability("Overwhelming Strength", 200)
    Athena = superhero.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
示例#15
0
def test_hero_add_ability():
    big_strength = superhero.Ability("Overwhelming Strength", 300)
    Athena = superhero.Hero("Athena")
    assert len(Athena.abilities) == 0
    Athena.add_ability(big_strength)
    assert len(Athena.abilities) == 1
    # Check for correct type
    assert "Ability" in str(Athena.abilities[0])
    assert Athena.abilities[0].name == "Overwhelming Strength"
示例#16
0
def test_hero_multi_weapon_attack():
    strength = superhero.Weapon("Overwhelming Strength", 200)
    sword_of_truth = superhero.Weapon("Sword of Truth", 700)
    Athena = superhero.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
示例#17
0
def test_hero_defense_standard_deviation():
    willow_waffle = superhero.Hero("Willow Waffle")
    strength = random.randint(400, 30000)
    willow = superhero.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
示例#18
0
def test_hero_attack_standard_deviation():
    willow_waffle = superhero.Hero("Willow Waffle")
    strength = random.randint(400, 30000)
    travel_agent = superhero.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
示例#19
0
def test_hero_ability_attack_standard_deviation():
    willow_waffle = superhero.Hero("Willow Waffle")
    strength = random.randint(400, 30000)
    willow = superhero.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
示例#20
0
def test_hero_equip_armor():
    jodie = superhero.Hero("Jodie Foster")
    gauntlets = superhero.Armor("Gauntlets", 30)
    jodie.add_armor(gauntlets)
    assert len(jodie.armors) == 1
    assert jodie.armors[0].name == "Gauntlets"
示例#21
0
def test_dead_hero_defense():
    hero = superhero.Hero("Vlaad", 0)
    garlic = superhero.Armor("Garlic", 30000)
    hero.add_ability(garlic)
    assert hero.defend() == 0
示例#22
0
def test_hero_defense():
    jodie = superhero.Hero("Jodie Foster")
    gauntlets = superhero.Armor("Gauntlets", 30)
    jodie.add_armor(gauntlets)
    defense = jodie.defend()
    assert defense >= 0 and defense <= 30
示例#23
0
def test_hero_start_health():
    hero = superhero.Hero("Jodie Foster", 300)
    assert hero.starting_health == 300
示例#24
0
def test_hero_init_new_health():
    hero = superhero.Hero("Jodie Foster", 600)
    assert hero.current_health == 600
示例#25
0
def test_hero_default_health():
    jodie = superhero.Hero("Jodie Foster")
    assert jodie.current_health == 100
示例#26
0
def test_armor():
    armor = superhero.Hero("The Ring", 200)
    for _ in range(0, 500):
        defense = armor.defend()
        assert (defense <= 200 and defense >= 0)
示例#27
0
def test_hero_instance():
    Athena = superhero.Hero("Athena")
    assert Athena
示例#28
0
def test_hero_weapon_equip():
    sans = superhero.Hero("Comic Sans")
    weapon = superhero.Weapon("Garlic Hot Sauce", 400)
    sans.add_ability(weapon)
    assert len(sans.abilities) == 1
    assert sans.abilities[0].name == "Garlic Hot Sauce"