예제 #1
0
def test_hero_defend_multi_armor():
    jodie = superheroes.Hero("Jodie Foster")
    gauntlets = superheroes.Armor("Gauntlets", 4000)
    science = superheroes.Armor("Science", 9000)
    jodie.add_armor(gauntlets)
    jodie.add_armor(science)
    defend = jodie.defend(10000)
    assert defend <= 13000 and defend >= 0
예제 #2
0
def test_hero_defense_mean_value():
    athena = superheroes.Hero("Athena")
    strength = random.randint(400, 30000)
    big_strength = superheroes.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(total_attack)
        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
예제 #3
0
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 superheroes.Armor(name, power)
예제 #4
0
def test_team_attack_deaths():
    team_one = superheroes.Team("One")
    jodie = superheroes.Hero("Jodie Foster")
    aliens = superheroes.Ability("Alien Friends", 10000)
    jodie.add_ability(aliens)
    team_one.add_hero(jodie)
    team_two = superheroes.Team("Two")
    athena = superheroes.Hero("Athena")
    socks = superheroes.Armor("Socks", 10)
    athena.add_armor(socks)
    team_two.add_hero(athena)
    assert team_two.members[0].deaths == 0
    team_two.kill_team()
    assert team_two.members[0].deaths == 1
예제 #5
0
def test_hero_defense_standard_deviation():
    willow_waffle = superheroes.Hero("Willow Waffle")
    strength = random.randint(400, 30000)
    willow = superheroes.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(total_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
예제 #6
0
def test_hero_equip_armor():
    jodie = superheroes.Hero("Jodie Foster")
    gauntlets = superheroes.Armor("Gauntlets", 30)
    jodie.add_armor(gauntlets)
    assert len(jodie.armor) == 1
    assert jodie.armor[0].name == "Gauntlets"
예제 #7
0
def test_dead_hero_defense():
    hero = superheroes.Hero("Vlaad", 0)
    garlic = superheroes.Armor("Garlic", 30000)
    hero.add_ability(garlic)
    assert hero.defend(3000) == 0
예제 #8
0
def test_hero_defense():
    jodie = superheroes.Hero("Jodie Foster")
    gauntlets = superheroes.Armor("Gauntlets", 30)
    jodie.add_armor(gauntlets)
    defense = jodie.defend(20)
    assert defense >= 0 and defense <= 30