diff --git a/tests/unit/motors/test_point_mass_motor.py b/tests/unit/motors/test_point_mass_motor.py index 3981380ab..1eb248723 100644 --- a/tests/unit/motors/test_point_mass_motor.py +++ b/tests/unit/motors/test_point_mass_motor.py @@ -4,6 +4,11 @@ def test_init_required_args(): + """Tests that PointMassMotor initializes correctly with required arguments. + + Verifies that the motor is properly instantiated and that basic properties + like dry_mass, propellant_initial_mass, and burn_time are correctly set. + """ m = PointMassMotor( thrust_source=10, dry_mass=1.0, propellant_initial_mass=0.5, burn_time=1.2 ) @@ -15,6 +20,12 @@ def test_init_required_args(): def test_missing_required_args_raises(): + """Tests that PointMassMotor raises errors for missing required arguments. + + Verifies that ValueError is raised when propellant_initial_mass is None + or when burn_time is not provided with constant thrust. Also verifies + TypeError is raised for invalid thrust_source types. + """ # TODO: in the future we would like to capture specific RocketPy Exceptions with pytest.raises(ValueError): PointMassMotor(10, 1.0, None, 1) @@ -25,6 +36,11 @@ def test_missing_required_args_raises(): def test_exhaustvelocity_and_totalmassflowrate(): + """Tests that exhaust_velocity and total_mass_flow_rate return Function objects. + + Verifies that both properties are callable functions with get_value method, + which is required for numerical evaluation during simulation. + """ m = PointMassMotor( thrust_source=10, dry_mass=1.0, propellant_initial_mass=1.0, burn_time=2.0 ) @@ -35,6 +51,11 @@ def test_exhaustvelocity_and_totalmassflowrate(): def test_zero_inertias(): + """Tests that all propellant inertia components are zero for point mass motor. + + Verifies that propellant_I_11, propellant_I_22, and propellant_I_33 all + return zero, as expected for a point mass model without rotational dynamics. + """ m = PointMassMotor( thrust_source=10, dry_mass=1.0, propellant_initial_mass=1.0, burn_time=2.0 ) @@ -44,6 +65,11 @@ def test_zero_inertias(): def test_callable_thrust(): + """Tests that PointMassMotor accepts a callable function as thrust_source. + + Verifies that when a lambda function is used for thrust_source, the motor + correctly evaluates thrust values at different times. + """ m = PointMassMotor( thrust_source=lambda t: 100 * t, dry_mass=2, diff --git a/tests/unit/rocket/test_point_mass_rocket.py b/tests/unit/rocket/test_point_mass_rocket.py index 49e5cf806..c9ad709c9 100644 --- a/tests/unit/rocket/test_point_mass_rocket.py +++ b/tests/unit/rocket/test_point_mass_rocket.py @@ -3,6 +3,11 @@ def test_init_sets_basic_properties_correctly(): + """Tests that PointMassRocket initializes with correct basic properties. + + Verifies that radius, mass, motor assignment, and zero inertias are + correctly set when a PointMassRocket is created and a motor is added. + """ motor = PointMassMotor(10, 1.0, 0.5, 1.0) rocket = PointMassRocket( radius=0.05, @@ -19,7 +24,11 @@ def test_init_sets_basic_properties_correctly(): def test_structural_and_total_mass(): - """Test structural and total mass properties of point mass rocket.""" + """Tests structural and total mass properties of PointMassRocket. + + Verifies that the rocket's structural mass and total mass (including motor + dry mass and propellant) are calculated correctly at time t=0. + """ motor = PointMassMotor(10, 1.0, 1.1, 2.0) rocket = PointMassRocket( radius=0.03, @@ -37,7 +46,11 @@ def test_structural_and_total_mass(): def test_add_motor_overwrites(): - """Test that adding a motor overwrites the previous motor.""" + """Tests that adding a new motor to PointMassRocket overwrites the previous motor. + + Verifies that when add_motor is called multiple times, only the most + recently added motor is retained. + """ motor1 = PointMassMotor(10, 1, 1.1, 2.0) motor2 = PointMassMotor(20, 2, 1.5, 3.0) rocket = PointMassRocket(0.02, 1.0, 0.0, 0.2, 0.5) diff --git a/tests/unit/simulation/test_flight_3dof.py b/tests/unit/simulation/test_flight_3dof.py index ee219ce95..a44448baa 100644 --- a/tests/unit/simulation/test_flight_3dof.py +++ b/tests/unit/simulation/test_flight_3dof.py @@ -8,11 +8,13 @@ @pytest.fixture def point_mass_motor(): - """Simple PointMassMotor for 3-DOF tests. + """Creates a simple PointMassMotor for 3-DOF flight tests. Returns ------- rocketpy.PointMassMotor + A point mass motor with constant thrust of 10 N, 1.0 kg dry mass, + 0.5 kg propellant mass, and 2.2 s burn time. """ return PointMassMotor( thrust_source=10, @@ -24,11 +26,18 @@ def point_mass_motor(): @pytest.fixture def point_mass_rocket(point_mass_motor): - """Simple PointMassRocket for 3-DOF tests. + """Creates a simple PointMassRocket for 3-DOF flight tests. + + Parameters + ---------- + point_mass_motor : rocketpy.PointMassMotor + The motor to be added to the rocket. Returns ------- rocketpy.PointMassRocket + A point mass rocket with 0.05 m radius, 2.0 kg mass, and the + provided motor attached at position 0. """ rocket = PointMassRocket( radius=0.05, @@ -44,7 +53,15 @@ def point_mass_rocket(point_mass_motor): def test_simulation_mode_sets_3dof_with_point_mass_rocket( example_plain_env, point_mass_rocket ): - """Test that simulation mode is correctly set to 3 DOF.""" + """Tests that simulation mode is correctly set to 3 DOF for PointMassRocket. + + Parameters + ---------- + example_plain_env : rocketpy.Environment + A basic environment fixture for flight simulation. + point_mass_rocket : rocketpy.PointMassRocket + A point mass rocket fixture for 3-DOF simulation. + """ flight = Flight( rocket=point_mass_rocket, environment=example_plain_env, @@ -55,7 +72,18 @@ def test_simulation_mode_sets_3dof_with_point_mass_rocket( def test_3dof_simulation_mode_warning(example_plain_env, point_mass_rocket): - """Test that a warning is issued when 6 DOF is requested with PointMassRocket.""" + """Tests that a warning is issued when 6 DOF mode is requested with PointMassRocket. + + When a PointMassRocket is used with simulation_mode="6 DOF", the Flight + class should emit a UserWarning and automatically switch to 3 DOF mode. + + Parameters + ---------- + example_plain_env : rocketpy.Environment + A basic environment fixture for flight simulation. + point_mass_rocket : rocketpy.PointMassRocket + A point mass rocket fixture for 3-DOF simulation. + """ with pytest.warns(UserWarning): flight = Flight( rocket=point_mass_rocket, @@ -69,7 +97,18 @@ def test_3dof_simulation_mode_warning(example_plain_env, point_mass_rocket): def test_u_dot_generalized_3dof_returns_valid_result( example_plain_env, point_mass_rocket ): - """Test that 3-DOF equations of motion return valid results.""" + """Tests that 3-DOF equations of motion return valid derivative results. + + Verifies that the u_dot_generalized_3dof method returns a list or numpy + array representing the state derivative vector. + + Parameters + ---------- + example_plain_env : rocketpy.Environment + A basic environment fixture for flight simulation. + point_mass_rocket : rocketpy.PointMassRocket + A point mass rocket fixture for 3-DOF simulation. + """ flight = Flight( rocket=point_mass_rocket, environment=example_plain_env, @@ -82,7 +121,15 @@ def test_u_dot_generalized_3dof_returns_valid_result( def test_invalid_simulation_mode(example_plain_env, calisto): - """Test that invalid simulation mode raises ValueError.""" + """Tests that invalid simulation mode raises ValueError. + + Parameters + ---------- + example_plain_env : rocketpy.Environment + A basic environment fixture for flight simulation. + calisto : rocketpy.Rocket + The Calisto rocket fixture from the test suite. + """ with pytest.raises(ValueError): Flight( rocket=calisto,