def test_baro_pressure_at_10000m(): test_rocket = rm.Rocket() test_rocket.baro = sensors.Baro_Pressure_Sensor() test_rocket.temperature = -49.86 test_rocket.altitude = 10000 assert (abs(test_rocket.baro.update(test_rocket) - 26.5162) <= rm.TOLERANCE)
def test_baro_pressure_at_ground(): test_rocket = rm.Rocket() test_rocket.baro = sensors.Baro_Pressure_Sensor() test_rocket.temperature = 15.04 test_rocket.altitude = 0 assert (abs(test_rocket.baro.update(test_rocket) - 101.4009) <= rm.TOLERANCE)
def test_velocity_uv_with_no_velocity(): """ Test velocity_uv() for no velocity (velocity vector is zero vector). """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([0, 0, 0]) assert np.all(test_rocket.velocity_uv() == np.array([0, 0, 0]))
def test_speed_with_floats(): """ Test speed() for velocity vector with floats. """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([2.5, 3.5, 4.5]) assert test_rocket.speed() == np.sqrt(38.75)
def test_speed_with_negative_ints(): """ Test speed() for velocity vector with negative integers. """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([-1, -1, -1]) assert test_rocket.speed() == np.sqrt(3)
def test_velocity_uv_with_negative_ints(): """ Test velocity_uv() for velocity vector with negative integers. """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([-1, -1, -1]) assert np.all(test_rocket.velocity_uv() == np.array( [(-1 / np.sqrt(3)), (-1 / np.sqrt(3)), (-1 / np.sqrt(3))]))
def test_velocity_uv_with_positive_ints(): """ Test velocity_uv() for velocity vector with positive integers. """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([1, 1, 1]) assert np.all(test_rocket.velocity_uv() == np.array( [(1 / np.sqrt(3)), (1 / np.sqrt(3)), (1 / np.sqrt(3))]))
def test_speed_with_no_velocity(): """ Test speed() for no velocity (velocity vector is zero vector). """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([0, 0, 0]) assert test_rocket.speed() == 0
def test_update_thrust_with_no_thrust_and_def_orientation(): """ Test update_thrust() for no thrust and default orientation (thrust is the zero vector). """ test_rocket = rm.Rocket() current_time = 0 thrust_after_update = np.array([0, 0, 0]) new_thrust = test_rocket.update_thrust(current_time) np.testing.assert_allclose(new_thrust, thrust_after_update, atol=rm.TOLERANCE)
def test_velocity_uv_with_floats(): """ Test velocity_uv() for velocity vector with floats. """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([2.5, 3.5, 4.5]) assert np.all(test_rocket.velocity_uv() == np.array( [(2.5 / np.sqrt(38.75)), (3.5 / np.sqrt(38.75)), (4.5 / np.sqrt(38.75))]))
def test_drag_with_no_velocity(mocker): """ Test drag_force() for no velocity (velocity vector is zero vector). """ test_rocket = rm.Rocket() mocker.patch('rocket_math.Rocket.speed', return_value=0) mocker.patch('rocket_math.Rocket.velocity_uv', return_value=np.array([0, 0, 0])) mocker.patch('rocket_math.Rocket.air_density', return_value=1.22) assert np.all(test_rocket.drag_force() == np.array([0, 0, 0]))
def test_update_velocity_with_vel_and_accel_floats(): """ Test update_velocity() for velocity and acceleration vectors with floats. """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([1.5, 2.5, 3.5]) test_rocket.world_acceleration = np.array([1.5, 2.5, 3.5]) delta_time = 1 assert np.all(test_rocket.update_velocity(delta_time) == np.array([3, 5, 7]))
def test_update_velocity_with_neg_vel_and_accel_ints(): """ Test update_velocity() for velocity and acceleration vectors with negative integers and time change. """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([-1, -1, -1]) test_rocket.world_acceleration = np.array([-1, -1, -1]) delta_time = 1 assert np.all(test_rocket.update_velocity(delta_time) == np.array([-2, -2, -2]))
def test_update_position_with_neg_z_and_no_vel(): """ Test update_position() for position vector with negative z component and no velocity vector. """ test_rocket = rm.Rocket() test_rocket.position = np.array([1.5, 2.5, -3.5]) test_rocket.velocity = np.array([0, 0, 0]) delta_time = 1 assert np.all(test_rocket.update_position(delta_time) == np.array([1.5, 2.5, 0]))
def test_update_position_with_neg_position_and_vel_ints(): """ Test update_position() for position and velocity vectors with negative integers and time change. """ test_rocket = rm.Rocket() test_rocket.position = np.array([-1, -1, -1]) test_rocket.velocity = np.array([-1, -1, -1]) delta_time = 1 assert np.all(test_rocket.update_position(delta_time) == np.array([-2, -2, 0]))
def test_update_position_with_big_neg_position_and_pos_vel_ints(): """ Test update_position() for position vector with negative integers and velocity vector with positive integers (position magnitude is bigger). """ test_rocket = rm.Rocket() test_rocket.position = np.array([-3, -3, -3]) test_rocket.velocity = np.array([1, 1, 1]) delta_time = 1 assert np.all(test_rocket.update_position(delta_time) == np.array([-2, -2, 0]))
def test_update_position_with_pos_int_position_and_no_time_change(): """ Test update_position() for position and velocity vectors with positive integers and no time change. """ test_rocket = rm.Rocket() test_rocket.position = np.array([1, 1, 1]) test_rocket.velocity = np.array([1, 1, 1]) delta_time = 0 assert np.all(test_rocket.update_position(delta_time) == np.array([1, 1, 1]))
def test_update_position_with_pos_int_position_and_no_vel(): """ Test update_position() for position vector with positive integers and time change but no velocity vector. """ test_rocket = rm.Rocket() test_rocket.position = np.array([1, 1, 1]) test_rocket.velocity = np.array([0, 0, 0]) delta_time = 1 assert np.all(test_rocket.update_position(delta_time) == np.array([1, 1, 1]))
def test_update_position_no_position_or_vel(): """ Test update_position() for no position or velocity (position and velocity vectors are zero vectors). """ test_rocket = rm.Rocket() test_rocket.position = np.array([0, 0, 0]) test_rocket.velocity = np.array([0, 0, 0]) delta_time = 1 assert np.all(test_rocket.update_position(delta_time) == np.array([0, 0, 0]))
def test_update_velocity_with_no_vel_or_accel(): """ Test update_velocity() for no velocity or acceleration (velocity and acceleration vectors are zero vectors). """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([0, 0, 0]) test_rocket.world_acceleration = np.array([0, 0, 0]) delta_time = 1 assert np.all(test_rocket.update_velocity(delta_time) == np.array([0, 0, 0]))
def test_update_velocity_with_big_neg_vel_and_pos_accel_ints(): """ Test update_velocity() for velocity vector with negative integers and acceleration vector with positive integers (velocity magnitude is bigger). """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([-3, -3, -3]) test_rocket.world_acceleration = np.array([1, 1, 1]) delta_time = 1 assert np.all(test_rocket.update_velocity(delta_time) == np.array([-2, -2, -2]))
def test_update_position_with_only_neg_velocity(): """ Test update_position() for only velocity vector with negative floats and no position vector. """ test_rocket = rm.Rocket() test_rocket.position = np.array([0, 0, 0]) test_rocket.velocity = np.array([-1.5, -2.5, -3.5]) delta_time = 1 assert np.all(test_rocket.update_position(delta_time) == np.array([-1.5, -2.5, 0]))
def test_update_position_with_position_and_vel_floats(): """ Test update_position() for position and velocity vectors with positive floats. """ test_rocket = rm.Rocket() test_rocket.position = np.array([1.5, 2.5, 3.5]) test_rocket.velocity = np.array([1.5, 2.5, 3.5]) delta_time = 1 assert np.all(test_rocket.update_position(delta_time) == np.array([3, 5, 7]))
def test_update_velocity_with_pos_vel_and_no_accel_ints(): """ Test update_velocity() for velocity vector with positive integers and time change but no acceleration. """ test_rocket = rm.Rocket() test_rocket.velocity = np.array([1, 1, 1]) test_rocket.world_acceleration = np.array([0, 0, 0]) delta_time = 1 assert np.all(test_rocket.update_velocity(delta_time) == np.array([1, 1, 1]))
def test_body_acceleration_zeros(): """ Test update_body_acceleration() using a zero vector """ test_rocket = rm.Rocket() test_rocket.accelerometer = sensors.Accelerometer() test_rocket.orientation = Quaternion(axis=[1, 1, 1], angle=np.pi / 2).elements test_rocket.world_acceleration = np.array([0, 0, 0]) body_acceleration_after_rotate = np.array([0, 0, 0]) new_body_acceleration = test_rocket.accelerometer.update(test_rocket) assert np.all(body_acceleration_after_rotate == new_body_acceleration)
def test_update_thrust_with_pos_thrust_and_def_orientation(): """ Test update_thrust() for thrust vector with positive integers and default orientation: orientation = np.array([1.0, 0.0, 0.0, 0.0]) # identity quaternion """ test_rocket = rm.Rocket() test_rocket.burn_time = 10 test_rocket.thrust = np.array([1, 1, 1]) current_time = 0 thrust_after_update = np.array([1, 1, 1]) new_thrust = test_rocket.update_thrust(current_time) np.testing.assert_allclose(new_thrust, thrust_after_update, atol=rm.TOLERANCE)
def test_update_thrust_with_greater_current_time(): """ Test update_thrust() for current time greater than burn time. thrust = [1, 1, 1] orienation is axis of [1, 0, 0] with angle pi/2 """ test_rocket = rm.Rocket() test_rocket.burn_time = 10 test_rocket.thrust = np.array([1, 1, 1]) current_time = 20 test_rocket.orientation = Quaternion(axis=[1, 0, 0], angle=(np.pi / 2)).elements assert np.all(test_rocket.update_thrust(current_time) == np.array([0, 0, 0]))
def test_magnetic_field_negative_integers(): test_rocket = rm.Rocket() test_rocket.magnetometer = sensors.Magnetometer() test_rocket.orientation = Quaternion(axis=[1, 0, 1], angle=np.pi / 2).elements test_rocket.world_mag_field[3] = -1 test_rocket.world_mag_field[4] = -1 test_rocket.world_mag_field[5] = -3 mag_field_after_rotate = np.array([1.707107, -2.828427, 0.292893]) new_mag_field = test_rocket.magnetometer.update(test_rocket) np.testing.assert_allclose(new_mag_field, mag_field_after_rotate, atol=rm.TOLERANCE)
def test_magnetic_field_zeros(): """ Test update_magnetic_field() using a zero vector """ test_rocket = rm.Rocket() test_rocket.magnetometer = sensors.Magnetometer() test_rocket.orientation = Quaternion(axis=[1, 1, 1], angle=np.pi / 2).elements mag_field_after_rotate = np.array([0, 0, 0]) new_mag_field = test_rocket.magnetometer.update(test_rocket) np.testing.assert_allclose(new_mag_field, mag_field_after_rotate, atol=rm.TOLERANCE)
def test_body_acceleration_180_degrees(): """ Test update_body_acceleration() at an angle of 180 degrees """ test_rocket = rm.Rocket() test_rocket.accelerometer = sensors.Accelerometer() test_rocket.orientation = Quaternion(axis=[1, 0, 1], angle=np.pi).elements test_rocket.world_acceleration = np.array([1, 1, 1]) body_acceleration_after_rotate = np.array([1, -1, 1]) new_body_acceleration = test_rocket.accelerometer.update(test_rocket) np.testing.assert_allclose(new_body_acceleration, body_acceleration_after_rotate, atol=rm.TOLERANCE)