Ejemplo n.º 1
0
def test_hero_add_multi_ability():
    big_strength = superhero.Ability("Overwhelming Strength", 300)
    speed = superhero.Ability("Lightning Speed", 500)
    Athena = superhero.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
    # Check for correct type
    assert "Ability" in str(Athena.abilities[0])
    assert Athena.abilities[0].name == "Overwhelming Strength"
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def test_ability_attack():
    # Test for correct attack value
    test_runs = 400
    big_strength = superhero.Ability("Overwhelming Strength", 400)
    for _ in range(0, test_runs):
        attack = big_strength.attack()
        assert attack >= 0 and attack <= 400
Ejemplo n.º 5
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)
Ejemplo n.º 6
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
Ejemplo n.º 7
0
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 superhero.Ability(name, power)
Ejemplo n.º 8
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
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
Ejemplo n.º 10
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
Ejemplo n.º 11
0
def test_ability_name():
    # Test for Correct Name
    big_strength = superhero.Ability("Overwhelming Strength", 300)
    assert big_strength.name == "Overwhelming Strength"
Ejemplo n.º 12
0
def test_ability_instance():
    # Test instantiation without error
    big_strength = superhero.Ability("Overwhelming Strength", 300)
    assert big_strength