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 } })
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}"
def _get_sensors_for_assertion(ship_orientation={}, sensor_orientation={}, scan_direction=None, sensor_focus=89, has_power=True): reactor = Reactor(max_output=200) panels = { F"{direction}_panel": ShipPanel(side=direction, sensors=[ Sensor(base_range=2000, focus=sensor_focus, pitch=sensor_orientation.get(PITCH, 90), yaw=sensor_orientation.get(YAW, 90)) ]) for direction in DIRECTIONS } ship = Ship( **{ **panels, "reactors": [reactor] if has_power else [], PITCH: ship_orientation.get(PITCH, 0), ROLL: ship_orientation.get(ROLL, 0), YAW: ship_orientation.get(YAW, 0), }) if scan_direction is None: sensors = [ sensor for panel in ship.panels.values() for sensor in panel.sensors ] else: sensors = [sensor for sensor in ship.panels[scan_direction].sensors] return sensors
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"
def test_current_force_status_report(): thruster = Thruster(max_force=15) Ship(port_panel=ShipPanel(side=PORT, thrusters=[thruster])) reported_force = thruster.status_report["current_force"] actual_force = thruster.power_adjusted_current_force assert reported_force == actual_force, \ "Thruster current_force is innacurately reported"
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
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
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}"
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 } })
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"
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"
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"
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"
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"
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"
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"
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"
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"
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"
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"
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"
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"
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"
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"