Exemplo n.º 1
0
def test_string_representation_has_level():
    archer = Archer.create(level=3)

    expected_str = f"A(3)"

    assert str(
        archer
    ) == expected_str, "Expected level 3 archer to be represented as 'A(3)'"
Exemplo n.º 2
0
def test_add_unit_to_army(army, army_units):
    new_unit = Archer.create(level=5)
    initial_health = sum(map(lambda u: u.health, army_units))
    initial_speed = min(map(lambda u: u.speed, army_units))
    initial_level = sum(map(lambda u: u.level, army_units))

    expected_health = initial_health + new_unit.health
    expected_speed = min(initial_speed, new_unit.speed)
    expected_level = initial_level + new_unit.level

    army += new_unit

    assert army.health == expected_health, f"New army health should be {expected_health}, but was {army.health}"
    assert army.speed == expected_speed, f"New army speed should be {expected_speed}, but was {army.speed}"
    assert army.level == expected_level, f"New army level should be {expected_level}, but was {army.level}"
Exemplo n.º 3
0
def test_create_sets_name_based_on_num_units():
    # This is the current number of units
    Archer.NUM_UNITS = 3
    archer = Archer.create(level=1)

    assert archer.name == "Archer 4", "Name of the new unit should use Archer.NUM_UNITS"
Exemplo n.º 4
0
def test_create_increases_num_units():
    Archer.NUM_UNITS = 0
    _ = Archer.create(level=1)

    assert Archer.NUM_UNITS == 1, "Archer.NUM_UNITS should increase by 1 after calling create"
Exemplo n.º 5
0
def test_archer_has_defense():
    archer = Archer.create(level=1)

    assert isinstance(archer, Defense), "Archer should have Defense"
Exemplo n.º 6
0
def test_archer_has_ranged_attack():
    archer = Archer.create(level=1)

    assert isinstance(archer, RangedAttack), "Archer should have RangedAttack"
Exemplo n.º 7
0
def test_archer_short_text():
    archer = Archer.create(level=1)

    assert archer.short_text == "A", "Short text for the archer class should be 'A'"
Exemplo n.º 8
0
def army_units():
    unit1 = Archer.create(level=2)
    unit2 = Swordsman.create(level=3)
    unit3 = Apprentice.create(level=1)

    return [unit1, unit2, unit3]