Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
0
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 superhero.Weapon(name, power)
Exemplo n.º 5
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
Exemplo n.º 6
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(
        "Standard Deviation Cannot be 0.\nRandom Numbers not generated for attack."
    )
    assert standard_dev != 0.0
Exemplo n.º 7
0
def test_weapon_attack():
    big_stick = superhero.Weapon("Overwhelming Stick", 200)
    test_runs = 100
    for _ in range(0, test_runs):
        attack = big_stick.attack()
        assert attack <= 200 and attack >= 100
Exemplo n.º 8
0
def test_weapon_instance():
    big_stick = superhero.Weapon("Overwhelming Stick", 200)
    assert "Weapon" in str(big_stick)
Exemplo n.º 9
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"