Skip to content

Commit 7f1ebef

Browse files
TST: Add unit tests for evaluate_reduced_mass and remove TODO (#1051)
Removes the TODO comment in rocketpy/rocket/rocket.py asking for tests for reduced_mass values. Adds test_evaluate_reduced_mass_without_motor, test_evaluate_reduced_mass_empty_motor, and test_evaluate_reduced_mass_with_motor to tests/unit/rocket/test_rocket.py.
1 parent eb46d10 commit 7f1ebef

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

rocketpy/rocket/rocket.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ def evaluate_reduced_mass(self):
612612
self.reduced_mass : Function
613613
Function of time expressing the reduced mass of the rocket.
614614
"""
615-
# TODO: add tests for reduced_mass values
616615
# Make sure there is a motor associated with the rocket
617616
if self.motor is None:
618617
logger.warning("Please associate this rocket with a motor!")

tests/unit/rocket/test_rocket.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,3 +996,52 @@ def test_power_drag_exposed_as_function_objects_and_inputs_preserved():
996996
# Raw user input is preserved for serialization / round-tripping.
997997
assert rocket._power_off_drag_input == off_input
998998
assert rocket._power_on_drag_input == on_input
999+
1000+
1001+
def test_evaluate_reduced_mass_without_motor(calisto_motorless):
1002+
"""Test evaluate_reduced_mass returns False when there is no motor
1003+
associated with the rocket (self.motor is None).
1004+
"""
1005+
# Arrange
1006+
rocket = calisto_motorless
1007+
rocket.motor = None
1008+
1009+
# Act
1010+
result = rocket.evaluate_reduced_mass()
1011+
1012+
# Assert
1013+
assert result is False
1014+
1015+
1016+
def test_evaluate_reduced_mass_empty_motor(calisto_motorless):
1017+
"""Test evaluate_reduced_mass returns a Function evaluating to 0 when
1018+
the motor is an EmptyMotor.
1019+
"""
1020+
# Arrange
1021+
rocket = calisto_motorless
1022+
1023+
# Act
1024+
reduced_mass = rocket.evaluate_reduced_mass()
1025+
1026+
# Assert
1027+
assert isinstance(reduced_mass, Function)
1028+
assert reduced_mass(0) == pytest.approx(0)
1029+
1030+
1031+
def test_evaluate_reduced_mass_with_motor(calisto):
1032+
"""Test evaluate_reduced_mass returns the correct Function when a motor
1033+
is associated with the rocket.
1034+
"""
1035+
# Arrange
1036+
rocket = calisto
1037+
dry_mass = rocket.dry_mass
1038+
prop_mass = rocket.motor.propellant_mass
1039+
1040+
# Act
1041+
reduced_mass = rocket.evaluate_reduced_mass()
1042+
1043+
# Assert
1044+
assert isinstance(reduced_mass, Function)
1045+
for t in [0.0, 1.0, 2.0, 3.0]:
1046+
expected = prop_mass(t) * dry_mass / (prop_mass(t) + dry_mass)
1047+
assert reduced_mass(t) == pytest.approx(expected)

0 commit comments

Comments
 (0)