def test_swap():
    """
    Tests swapping the tonnage on the ship and making sure the ship's values
    translate accordingly
    """
    ship = Spacecraft(200)

    armour = Armour("Titanium Steel")
    assert armour.tl == 7
    assert armour.protection == 2
    assert armour.hull_amount == 0.05
    assert armour.cost_by_hull_percentage == 0.05

    ship.add_armour(armour)
    assert ship.get_remaining_cargo() == 190
    assert ship.armour_total == 2
    assert ship.get_total_cost() == 8.4

    ship.set_tonnage(100)
    assert ship.get_remaining_cargo() == 95
    assert ship.armour_total == 2
    assert ship.get_total_cost() == 2.1

    ship.remove_armour(armour)
    assert ship.get_remaining_cargo() == 100
    assert ship.armour_total == 0
    assert ship.get_total_cost() == 2
def test_remove():
    """
    Tests removing a piece of armour from the ship
    """
    ship = Spacecraft(200)

    armour = Armour("Titanium Steel")
    assert armour.tl == 7
    assert armour.protection == 2
    assert armour.hull_amount == 0.05
    assert armour.cost_by_hull_percentage == 0.05

    ship.add_armour(armour)
    assert ship.get_remaining_cargo() == 190
    assert ship.armour_total == 2
    assert ship.get_total_cost() == 8.4

    ship.remove_armour(armour)
    assert ship.get_remaining_cargo() == 200
    assert ship.armour_total == 0
    assert ship.get_total_cost() == 8

    # testing for removing a non-attached armour piece
    ship.remove_armour(armour)
    assert ship.get_remaining_cargo() == 200
    assert ship.armour_total == 0
    assert ship.get_total_cost() == 8
def test_add():
    """
    Tests adding a piece of armour to a ship
    """
    ship = Spacecraft(200)

    armour = Armour("Titanium Steel")
    assert armour.tl == 7
    assert armour.protection == 2
    assert armour.hull_amount == 0.05
    assert armour.cost_by_hull_percentage == 0.05

    ship.add_armour(armour)
    assert ship.get_remaining_cargo() == 190
    assert ship.armour_total == 2
    assert ship.get_total_cost() == 8.4
示例#4
0
def test_set_tonnage():
    """
    Tests functionality of setting tonnage and the updates that comes with that
    """
    ship = Spacecraft(100)
    assert ship.get_remaining_cargo() == 100
    assert ship.get_total_cost() == 2.0
    assert ship.tonnage == 100
    assert ship.structure_hp == 2
    assert ship.hull_hp == 2
    assert ship.armour_total == 0

    ship.set_tonnage(200)
    assert ship.get_remaining_cargo() == 200
    assert ship.get_total_cost() == 8.0
    assert ship.tonnage == 200
    assert ship.structure_hp == 4
    assert ship.hull_hp == 4
    assert ship.armour_total == 0

    armour = Armour("Titanium Steel")
    ship.add_armour(armour)
    assert ship.get_remaining_cargo() == 190
    assert ship.get_total_cost() == 8.4
    assert ship.tonnage == 200
    assert ship.structure_hp == 4
    assert ship.hull_hp == 4
    assert ship.armour_total == 2

    ship.set_tonnage(100)
    assert ship.get_remaining_cargo() == 95
    assert ship.get_total_cost() == 2.1
    assert ship.tonnage == 100
    assert ship.armour_total == 2
    assert ship.structure_hp == 2
    assert ship.hull_hp == 2