Пример #1
0
def test_team_remove_unlisted():
    # Test that if no results found return 0
    team = SuperHeroes.Team("One")
    jodie = SuperHeroes.Hero("Jodie Foster")
    team.add_hero(jodie)
    code = team.remove_hero("Athena")
    assert code == 0
Пример #2
0
def test_hero_attack():
    flash = SuperHeroes.Hero("The Flash")
    assert flash.attack() == 0
    pesto = SuperHeroes.Ability("Pesto Sauce", 8000)
    flash.add_ability(pesto)
    attack = flash.attack()
    assert attack <= 8000 and attack >= 4000
Пример #3
0
def test_team_remove_hero():
    team = SuperHeroes.Team("One")
    jodie = SuperHeroes.Hero("Jodie Foster")
    team.add_hero(jodie)
    assert team.heroes[0].name == "Jodie Foster"
    team.remove_hero("Jodie Foster")
    assert len(team.heroes) == 0
Пример #4
0
def test_hero_attack_ability():
    big_strength = SuperHeroes.Ability("Overwhelming Strength", 30000)
    athena = SuperHeroes.Hero("Athena")
    assert athena.attack() == 0
    athena.add_ability(big_strength)
    attack = athena.attack()
    assert attack <= 30000 and attack >= 15000
Пример #5
0
def test_hero_attack_weapon():
    big_strength = SuperHeroes.Ability("Overwhelming Strength", 200)
    Athena = SuperHeroes.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
Пример #6
0
def test_hero_weapon_ability_attack():
    quickness = SuperHeroes.Ability("Quickness", 1300)
    sword_of_truth = SuperHeroes.Weapon("Sword of Truth", 700)
    Athena = SuperHeroes.Hero("Athena")
    Athena.add_ability(quickness)
    Athena.add_ability(sword_of_truth)
    assert len(Athena.abilities) == 2
    attack_avg(Athena, 0, 2000)
Пример #7
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()
    assert defend <= 13000 and defend >= 0
Пример #8
0
def test_hero_add_ability():
    big_strength = SuperHeroes.Ability("Overwhelming Strength", 300)
    Athena = SuperHeroes.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"
Пример #9
0
def test_print_heroes():
    team = SuperHeroes.Team("One")
    jodie = SuperHeroes.Hero("Jodie Foster")
    team.add_hero(jodie)
    athena = SuperHeroes.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
Пример #10
0
def test_hero_multi_weapon_attack():
    strength = SuperHeroes.Weapon("Overwhelming Strength", 200)
    sword_of_truth = SuperHeroes.Weapon("Sword of Truth", 700)
    Athena = SuperHeroes.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
Пример #11
0
def create_hero(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 = SuperHeroes.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
Пример #12
0
def test_ability_attack():
    # Test for correct attack value
    test_runs = 100
    big_strength = SuperHeroes.Ability("Overwhelming Strength", 400)
    for _ in range(0, test_runs):
        attack = big_strength.attack()
        assert attack <= 400 and attack >= 200
Пример #13
0
def test_ability_update_attack():
    big_strength = SuperHeroes.Ability("Overwhelming Strength", 300)
    big_strength.update_attack(400)
    test_runs = 100
    attack = 0
    for _ in range(0, test_runs):
        attack += big_strength.attack()
    assert attack <= (400 * test_runs) and attack >= (200 * test_runs)
Пример #14
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)
Пример #15
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 SuperHeroes.Weapon(name, power)
Пример #16
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 SuperHeroes.Ability(name, power)
Пример #17
0
def create_team(heroes=[]):
    teams = [
        "Orchids", "Red", "Blue", "Cheese Steaks", "Warriors", "49ers",
        "Marvel", "DC", "Rat Pack", "The Little Red Riding Hoods", "Team One",
        "Generic Team", "X-men", "Team Two", "Golden Champions",
        "Vegan Protectors", "The Cardinals", "Winky Bears", "Steelsmiths",
        "Boilermakers", "Nincompoops"
    ]
    name = teams[random.randint(0, len(teams) - 1)]
    team = SuperHeroes.Team(name)
    if len(heroes) > 0:
        for member in heroes:
            team.add_hero(member)

    return team
Пример #18
0
def test_revive_heroes():
    heroes = []
    for _ in range(0, 20):
        heroes.append(create_hero(health=60))

    team_one = SuperHeroes.Team("One")
    for hero in heroes:
        team_one.add_hero(hero)

    team_one.defend(300)
    for hero in team_one.heroes:
        assert hero.health == 45
    team_one.revive_heroes()
    for hero in team_one.heroes:
        assert hero.health == 60
Пример #19
0
def test_team_defend():
    heroes = []
    for _ in range(0, 20):
        heroes.append(create_hero(health=20))
        print(heroes[_].health)
    team_one = SuperHeroes.Team("One")
    for hero in heroes:
        team_one.add_hero(hero)

    deaths = team_one.defend(100)
    for hero in team_one.heroes:
        assert hero.health == 15

    assert deaths == 0

    assert team_one.defend(400) == 20
Пример #20
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.heroes[0].deaths == 0
    team_one.attack(team_two)
    assert team_two.heroes[0].deaths == 1
Пример #21
0
def test_hero_init_new_health():
    hero = SuperHeroes.Hero("Jodie Foster", 600)
    assert hero.health == 600
Пример #22
0
def test_weapon_instance():
    big_stick = SuperHeroes.Weapon("Overwhelming Stick", 200)
    assert "Weapon" in str(big_stick)
Пример #23
0
def test_weapon_attack():
    big_stick = SuperHeroes.Weapon("Overwhelming Stick", 200)
    test_runs = 100
    for _ in range(0, test_runs):
        attack = big_stick.attack()
        assert attack <= 200 and attack >= 0
Пример #24
0
def test_hero_instance():
    Athena = SuperHeroes.Hero("Athena")
    assert Athena
Пример #25
0
def test_armor():
    armor = SuperHeroes.Hero("The Ring", 200)
    for _ in range(0, 500):
        defense = armor.defend() <= 200
        assert (defense <= 200 and defense >= 0)
Пример #26
0
def test_hero_default_health():
    jodie = SuperHeroes.Hero("Jodie Foster")
    assert jodie.health == 100
Пример #27
0
def test_hero_start_health():
    hero = SuperHeroes.Hero("Jodie Foster", 300)
    assert hero.start_health == 300
Пример #28
0
def test_hero_equip_armor():
    jodie = SuperHeroes.Hero("Jodie Foster")
    gauntlets = SuperHeroes.Armor("Gauntlets", 30)
    jodie.add_armor(gauntlets)
    assert len(jodie.armors) == 1
    assert jodie.armors[0].name == "Gauntlets"
Пример #29
0
def test_dead_hero_defense():
    hero = SuperHeroes.Hero("Vlaad", 0)
    garlic = SuperHeroes.Armor("Garlic", 30000)
    hero.add_ability(garlic)
    assert hero.defend() == 0
Пример #30
0
def test_hero_defense():
    jodie = SuperHeroes.Hero("Jodie Foster")
    gauntlets = SuperHeroes.Armor("Gauntlets", 30)
    jodie.add_armor(gauntlets)
    defense = jodie.defend()
    assert defense >= 0 and defense <= 30