Skip to content

Commit 0cb0eb5

Browse files
committed
Tests created
The solid motor integrations test was created and the solid and hybrid motors unit tests were modified to add checks to the new only_radial_burning class and parameters. Also a correction was made in the hybrid unit tests to fix the test time.
1 parent d97ba24 commit 0cb0eb5

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

flight.json

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from unittest.mock import patch
2+
3+
@patch("matplotlib.pyplot.show")
4+
def test_solid_motor_info(mock_show, cesaroni_m1670):
5+
"""Tests the SolidMotor.all_info() method.
6+
7+
Parameters
8+
----------
9+
mock_show : mock
10+
Mock of the matplotlib.pyplot.show function.
11+
hybrid_motor : rocketpy.HybridMotor
12+
The SolidMotor object to be used in the tests.
13+
"""
14+
assert cesaroni_m1670.info() is None
15+
assert cesaroni_m1670.all_info() is None

tests/unit/test_hybridmotor.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_hybrid_motor_center_of_mass(hybrid_motor, spherical_oxidizer_tank):
121121
propellant_center_of_mass = propellant_balance / (grain_mass + oxidizer_mass)
122122
center_of_mass = balance / (grain_mass + oxidizer_mass + DRY_MASS)
123123

124-
for t in np.linspace(0, 100, 100):
124+
for t in np.linspace(0, BURN_TIME, 100):
125125
assert pytest.approx(
126126
hybrid_motor.center_of_propellant_mass(t)
127127
) == propellant_center_of_mass(t)
@@ -170,9 +170,45 @@ def test_hybrid_motor_inertia(hybrid_motor, spherical_oxidizer_tank):
170170
+ DRY_MASS * (-hybrid_motor.center_of_mass + CENTER_OF_DRY_MASS) ** 2
171171
)
172172

173-
for t in np.linspace(0, 100, 100):
173+
for t in np.linspace(0, BURN_TIME, 100):
174174
assert pytest.approx(hybrid_motor.propellant_I_11(t)) == propellant_inertia(t)
175175
assert pytest.approx(hybrid_motor.I_11(t)) == inertia(t)
176176

177177
# Assert cylindrical symmetry
178178
assert pytest.approx(hybrid_motor.propellant_I_22(t)) == propellant_inertia(t)
179+
180+
def test_hybrid_motor_only_radial_burn_behavior(hybrid_motor):
181+
"""
182+
Test if only_radial_burn flag in HybridMotor propagates to its SolidMotor
183+
and affects burn_area calculation.
184+
"""
185+
motor = hybrid_motor
186+
187+
# Activates the radial burning
188+
motor.solid.only_radial_burn = True
189+
assert motor.solid.only_radial_burn is True
190+
191+
# Calculates the expected initial area
192+
burn_area_radial = (
193+
2
194+
* np.pi
195+
* (motor.solid.grain_inner_radius(0) * motor.solid.grain_height(0))
196+
* motor.solid.grain_number
197+
)
198+
199+
assert np.isclose(motor.solid.burn_area(0), burn_area_radial, atol=1e-12)
200+
201+
# Deactivates the radial burning and recalculate the geometry
202+
motor.solid.only_radial_burn = False
203+
motor.solid.evaluate_geometry()
204+
assert motor.solid.only_radial_burn is False
205+
206+
# In this case the burning area also considers tha bases of the grain
207+
inner_radius = motor.solid.grain_inner_radius(0)
208+
outer_radius = motor.solid.grain_outer_radius
209+
burn_area_total = (
210+
burn_area_radial
211+
+ 2 * np.pi * (outer_radius**2 - inner_radius**2) * motor.solid.grain_number
212+
)
213+
assert np.isclose(motor.solid.burn_area(0), burn_area_total, atol=1e-12)
214+
assert motor.solid.burn_area(0) > burn_area_radial

tests/unit/test_solidmotor.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,32 @@ def test_reshape_thrust_curve_asserts_resultant_thrust_curve_correct(
279279

280280
assert thrust_reshaped[1][1] == 100 * (tuple_parametric[1] / 7539.1875)
281281
assert thrust_reshaped[7][1] == 2034 * (tuple_parametric[1] / 7539.1875)
282+
283+
def test_only_radial_burn_parameter_effect(cesaroni_m1670):
284+
# Tests if the only_radial_burn flag is properly set
285+
motor = cesaroni_m1670
286+
motor.only_radial_burn = True
287+
assert motor.only_radial_burn is True
288+
289+
# When only_radial_burn is active, burn_area should consider only radial area
290+
burn_area_radial = 2 * np.pi * (motor.grain_inner_radius(0) * motor.grain_height(0)) * motor.grain_number
291+
assert np.isclose(motor.burn_area(0), burn_area_radial, atol=1e-12)
292+
293+
def test_evaluate_geometry_updates_properties(cesaroni_m1670):
294+
# Checks if after instantiation, grain_inner_radius and grain_height are valid functions
295+
motor = cesaroni_m1670
296+
297+
assert hasattr(motor, "grain_inner_radius")
298+
assert hasattr(motor, "grain_height")
299+
300+
# Checks if the domain of grain_inner_radius function is consistent
301+
times = motor.grain_inner_radius.x_array
302+
values = motor.grain_inner_radius.y_array
303+
304+
assert times[0] == 0 # expected initial time
305+
assert values[0] == motor.grain_initial_inner_radius # expected initial inner radius
306+
assert values[-1] <= motor.grain_outer_radius # final inner radius should be less or equal than outer radius
307+
308+
# Evaluates without error
309+
val = motor.grain_inner_radius(0.5) # evaluate at intermediate time
310+
assert isinstance(val, float)

0 commit comments

Comments
 (0)