Ejemplo n.º 1
0
def _test_acceleration(direction,
                       expected_position,
                       orientation={},
                       keep_mass=True,
                       reactor_power=20):
    # Generate the components and build the ship
    thruster = Thruster(max_force=10.0)
    reactor = Reactor(max_output=reactor_power)
    panel = ShipPanel(side=directions.COUNTER_DIRECTIONS[direction],
                      thrusters=[thruster])
    ship = Ship(
        **{
            "reactors": [reactor],
            F"{direction}_panel": panel,
            directions.YAW: orientation.get(directions.YAW, 0),
            directions.ROLL: orientation.get(directions.ROLL, 0),
            directions.PITCH: orientation.get(directions.PITCH, 0),
        })

    # Set total mass to 1 in order to negate any mass affects on propulsion
    if not keep_mass:
        ship.mass = 1

    # Set thruster throttle to 50%
    for thruster in ship.get_thrusters_by_orientation(direction):
        thruster.throttle = 1.0

    # Apply acceleration for one tick
    ship.apply_acceleration_vectors()

    # Error
    assert ship.position == expected_position, \
        F"{ship.position} != {expected_position}"
Ejemplo n.º 2
0
def test_current_force_status_report_no_throttle():
    thruster = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[thruster]))
    thruster.throttle = 0.1
    reported_force = thruster.status_report["current_force"]
    actual_force = thruster.power_adjusted_current_force
    assert reported_force == actual_force, \
        "Thruster.power_adjusted_current_force is innacurately reported"
Ejemplo n.º 3
0
def _create_test_ship():
    return Ship(
        **{
            directions.YAW:
            0,
            directions.ROLL:
            0,
            directions.PITCH:
            0,
            "reactors": [Reactor(max_output=20)],
            "reaction_wheels": [
                ReactionWheel(
                    axis=axis, rotation=directions.FORWARD, max_force=15) for
                axis in [directions.YAW, directions.ROLL, directions.PITCH]
            ],
            **{
                F"{direction}_panel": ShipPanel(side=directions.COUNTER_DIRECTIONS[direction],
                                                thrusters=[
                                                    Thruster(max_force=10.0)
                                                ],
                                                sensors=[
                                                    Sensor(base_range=2000)
                                                ])
                for direction in directions.DIRECTIONS
            }
        })
Ejemplo n.º 4
0
def test_vector_status_report():
    ship = Ship(port_panel=ShipPanel(side=PORT,
                                     thrusters=[Thruster(max_force=15)]),
                reactors=[Reactor(max_output=100)])
    report_vector = Vector.from_list(ship.status_report["vector"].values())
    assert report_vector == ship.current_vector, \
        "Thruster vector is innacurately reported"
Ejemplo n.º 5
0
def _build_ship(direction, pos, orientation, throttle):
    # Generate the components and build the ship
    thruster = Thruster(max_force=10.0)
    reactor = Reactor(max_output=60)
    panel = ShipPanel(side=COUNTER_DIRECTIONS[direction], thrusters=[thruster])
    ship = Ship(
        **{
            "reactors": [reactor],
            F"{direction}_panel": panel,
            YAW: orientation.get(YAW, 0),
            ROLL: orientation.get(ROLL, 0),
            PITCH: orientation.get(PITCH, 0),
        })

    for thruster in ship.get_thrusters_by_orientation(direction):
        thruster.throttle = 1.0

    return ship
def test_thruster_degredation():
    # Generate the components and build the ship
    thruster = Thruster(max_force=10.0)
    panel = ShipPanel(
        side=directions.FORWARD,
        thrusters=[thruster]
    )
    ship = Ship(**{F"{directions.FORWARD}_panel": panel})

    # Set thruster throttle to 120%
    for thruster in ship.thrusters:
        thruster.throttle = 1.2

    # Apply acceleration for one hundred ticks
    for _ in range(0, 100):
        ship.apply_acceleration_vectors()

    # Error
    assert ship.thrusters[0].integrity == 0.996, \
        F"{ship.thrusters[0].integrity} != {0.996}"
Ejemplo n.º 7
0
def test_ship_mass_calculation():
    thruster = Thruster(max_force=10)
    ship = Ship(
        **{
            "reaction_wheels":
            [ReactionWheel(max_force=10, axis=directions.ROLL)],
            **{
                F"{side}_panel": ShipPanel(side=side, thrusters=[thruster])
                for side in directions.DIRECTIONS
            }
        })
    assert ship.mass == 70
Ejemplo n.º 8
0
def test_ship_dimension_calculation():
    thruster = Thruster(max_force=10)
    ship = Ship(
        **{
            "reaction_wheels":
            [ReactionWheel(max_force=10, axis=directions.ROLL)],
            **{
                F"{side}_panel": ShipPanel(side=side, thrusters=[thruster])
                for side in directions.DIRECTIONS
            }
        })
    assert ship.width == 2.8
    assert ship.height == 2.8
    assert ship.depth == 2.8
Ejemplo n.º 9
0
def _create_test_ship():
    return Ship(
        **{
            "reactors": [Reactor(max_output=2000)],
            "reaction_wheels": [
                ReactionWheel(
                    axis=axis, rotation=directions.CLOCKWISE, max_force=750)
                for axis in
                [directions.YAW, directions.ROLL, directions.PITCH]
            ] + [
                ReactionWheel(axis=axis,
                              rotation=directions.COUNTER_CLOCKWISE,
                              max_force=750) for axis in
                [directions.YAW, directions.ROLL, directions.PITCH]
            ],
            **{
                F"{direction}_panel": ShipPanel(
                    side=directions.COUNTER_DIRECTIONS[direction],
                    thrusters=[Thruster(max_force=50.0)],
                    sensors=[Sensor(base_range=1500.0, focus=90)],
                )
                for direction in directions.DIRECTIONS
            }
        })
Ejemplo n.º 10
0
def test_mass_status_report():
    ship = Ship(port_panel=ShipPanel(side=PORT,
                                     thrusters=[Thruster(max_force=15)]),
                reactors=[Reactor(max_output=100)])
    assert ship.status_report["mass"] == ship.mass, \
        "Thruster mass is innacurately reported"
Ejemplo n.º 11
0
def test_power_consumption_status_report():
    ship = Ship(port_panel=ShipPanel(side=PORT,
                                     thrusters=[Thruster(max_force=15)]),
                reactors=[Reactor(max_output=100)])
    assert ship.status_report["power_consumption"] == ship.power_consumption, \
        "Thruster power_consumption is innacurately reported"
Ejemplo n.º 12
0
def test_power_available_status_report():
    ship = Ship(port_panel=ShipPanel(side=PORT,
                                     thrusters=[Thruster(max_force=15)]),
                reactors=[Reactor(max_output=100)])
    assert ship.status_report["power_available"] == ship.power_available, \
        "Thruster vector is innacurately reported"
Ejemplo n.º 13
0
def test_max_force_status_report_lothruster_integrity():
    thruster = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[thruster]))
    thruster.degrade(0.2)
    assert thruster.status_report["max_force"] == thruster.max_force, \
        "Thruster max_force is innacurately reported"
Ejemplo n.º 14
0
def test_current_acceleration_status_report_lothruster_throttle():
    t = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[t]))
    t.throttle = 0.2
    assert t.status_report["current_acceleration"] == t.current_acceleration, \
        "Thruster current_acceleration is innacurately reported"
Ejemplo n.º 15
0
def test_mass_status_report():
    thruster = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[thruster]))
    assert thruster.status_report["mass"] == thruster.mass, \
        "Thruster mass is innacurately reported"
Ejemplo n.º 16
0
def test_low_integrity_status_report():
    thruster = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[thruster]))
    thruster.degrade(0.5)
    assert thruster.status_report["integrity"] == thruster.integrity, \
        "Thruster integrity is innacurately reported"
Ejemplo n.º 17
0
def test_degredation_rate_status_report_high_throttle():
    t = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[t]))
    t.throttle = 1.2
    assert t.status_report["degredation_rate"] == t.degredation_rate, \
        "Thruster degredation_rate is innacurately reported"
Ejemplo n.º 18
0
def test_is_active_status_report_no_integrity():
    thruster = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[thruster]))
    thruster.degrade(1)
    assert thruster.status_report["is_active"] == thruster.is_active, \
        "Thruster is_active is innacurately reported"
Ejemplo n.º 19
0
def test_throttle_status_report():
    thruster = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[thruster]))
    assert thruster.status_report["throttle"] == thruster.throttle, \
        "Thruster throttle is innacurately reported"
Ejemplo n.º 20
0
def test_power_consumption_high_throttle_status_report():
    t = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[t]))
    assert t.status_report["power_consumption"] == t.power_consumption, \
        "Thruster power_consumption is innacurately reported"
Ejemplo n.º 21
0
def test_powered_on_status_report():
    thruster = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[thruster]))
    thruster.powered_on = False
    assert thruster.status_report["powered_on"] == thruster.powered_on, \
        "Thruster powered_on is innacurately reported"
Ejemplo n.º 22
0
def test_thruster_mass_calculation():
    mass = Thruster(max_force=10).mass
    assert mass == 10 * KG_PER_THRUSTER_ACC
Ejemplo n.º 23
0
def test_current_acceleration_status_report_high_max_force():
    t = Thruster(max_force=150)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[t]))
    assert t.status_report["current_acceleration"] == t.current_acceleration, \
        "Thruster current_acceleration is innacurately reported"
Ejemplo n.º 24
0
def test_direction_status_report():
    thruster = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[thruster]))
    assert thruster.status_report["direction"] == thruster.direction, \
        "Thruster direction is innacurately reported"
Ejemplo n.º 25
0
def test_is_active_status_report_no_power():
    thruster = Thruster(max_force=15)
    Ship(port_panel=ShipPanel(side=PORT, thrusters=[thruster]))
    thruster.powered_on = False
    assert thruster.status_report["is_active"] == thruster.is_active, \
        "Thruster is_active is innacurately reported"