Skip to content

Commit 01efe3e

Browse files
committed
TST: implement parametrized test for motor coordinates.
1 parent 6493a1f commit 01efe3e

2 files changed

Lines changed: 84 additions & 29 deletions

File tree

tests/conftest.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,10 @@ def cesaroni_m1670(): # old name: solid_motor
111111

112112

113113
@pytest.fixture
114-
def calisto(cesaroni_m1670): # old name: rocket
114+
def calisto_motorless():
115115
"""Create a simple object of the Rocket class to be used in the tests. This
116-
is the same rocket that has been used in the getting started guide for
117-
years. The Calisto rocket is the Projeto Jupiter's project launched at the
118-
2019 Spaceport America Cup.
119-
120-
Parameters
121-
----------
122-
cesaroni_m1670 : rocketpy.SolidMotor
123-
An object of the SolidMotor class. This is a pytest fixture too.
116+
is the same rocket that has been used in the getting started guide for years
117+
but without a motor.
124118
125119
Returns
126120
-------
@@ -136,60 +130,71 @@ def calisto(cesaroni_m1670): # old name: rocket
136130
center_of_mass_without_motor=0,
137131
coordinate_system_orientation="tail_to_nose",
138132
)
133+
return calisto
134+
135+
136+
@pytest.fixture
137+
def calisto(calisto_motorless, cesaroni_m1670): # old name: rocket
138+
"""Create a simple object of the Rocket class to be used in the tests. This
139+
is the same rocket that has been used in the getting started guide for
140+
years. The Calisto rocket is the Projeto Jupiter's project launched at the
141+
2019 Spaceport America Cup.
142+
143+
Parameters
144+
----------
145+
calisto_motorless : rocketpy.Rocket
146+
An object of the Rocket class. This is a pytest fixture too.
147+
cesaroni_m1670 : rocketpy.SolidMotor
148+
An object of the SolidMotor class. This is a pytest fixture too.
149+
150+
Returns
151+
-------
152+
rocketpy.Rocket
153+
A simple object of the Rocket class
154+
"""
155+
calisto = calisto_motorless
139156
calisto.add_motor(cesaroni_m1670, position=-1.373)
140157
return calisto
141158

142159

143160
@pytest.fixture
144-
def calisto_liquid_modded(liquid_motor):
161+
def calisto_liquid_modded(calisto_motorless, liquid_motor):
145162
"""Create a simple object of the Rocket class to be used in the tests. This
146163
is an example of the Calisto rocket with a liquid motor.
147164
148165
Parameters
149166
----------
167+
calisto_motorless : rocketpy.Rocket
168+
An object of the Rocket class. This is a pytest fixture too.
150169
liquid_motor : rocketpy.LiquidMotor
151170
152171
Returns
153172
-------
154173
rocketpy.Rocket
155174
A simple object of the Rocket class
156175
"""
157-
calisto = Rocket(
158-
radius=0.0635,
159-
mass=14.426,
160-
inertia=(6.321, 6.321, 0.034),
161-
power_off_drag="data/calisto/powerOffDragCurve.csv",
162-
power_on_drag="data/calisto/powerOnDragCurve.csv",
163-
center_of_mass_without_motor=0,
164-
coordinate_system_orientation="tail_to_nose",
165-
)
176+
calisto = calisto_motorless
166177
calisto.add_motor(liquid_motor, position=-1.373)
167178
return calisto
168179

169180

170181
@pytest.fixture
171-
def calisto_hybrid_modded(hybrid_motor):
182+
def calisto_hybrid_modded(calisto_motorless, hybrid_motor):
172183
"""Create a simple object of the Rocket class to be used in the tests. This
173184
is an example of the Calisto rocket with a hybrid motor.
174185
175186
Parameters
176187
----------
188+
calisto_motorless : rocketpy.Rocket
189+
An object of the Rocket class. This is a pytest fixture too.
177190
hybrid_motor : rocketpy.HybridMotor
178191
179192
Returns
180193
-------
181194
rocketpy.Rocket
182195
A simple object of the Rocket class
183196
"""
184-
calisto = Rocket(
185-
radius=0.0635,
186-
mass=14.426,
187-
inertia=(6.321, 6.321, 0.034),
188-
power_off_drag="data/calisto/powerOffDragCurve.csv",
189-
power_on_drag="data/calisto/powerOnDragCurve.csv",
190-
center_of_mass_without_motor=0,
191-
coordinate_system_orientation="tail_to_nose",
192-
)
197+
calisto = calisto_motorless
193198
calisto.add_motor(hybrid_motor, position=-1.373)
194199
return calisto
195200

tests/test_rocket.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,56 @@ def test_add_fins_assert_cp_cm_plus_fins(calisto, dimensionless_calisto, m):
379379
)
380380

381381

382+
@pytest.mark.parametrize(
383+
"""cdm_position, grain_cm_position, nozzle_position, coord_direction,
384+
motor_position, expected_motor_cdm, expected_motor_cpp""",
385+
[
386+
(0.317, 0.397, 0, "nozzle_to_combustion_chamber", -1.373, -1.056, -0.976),
387+
(0, 0.08, -0.317, "nozzle_to_combustion_chamber", -1, -1, -0.92),
388+
(-0.317, -0.397, 0, "combustion_chamber_to_nozzle", -1.373, -1.056, -0.976),
389+
(0, -0.08, 0.317, "combustion_chamber_to_nozzle", -1, -1, -0.92),
390+
(1.317, 1.397, 1, "nozzle_to_combustion_chamber", -2.373, -1.056, -0.976),
391+
],
392+
)
393+
def test_add_motor_coordinates(
394+
calisto_motorless,
395+
cdm_position,
396+
grain_cm_position,
397+
nozzle_position,
398+
coord_direction,
399+
motor_position,
400+
expected_motor_cdm,
401+
expected_motor_cpp,
402+
):
403+
example_motor = SolidMotor(
404+
thrust_source="data/motors/Cesaroni_M1670.eng",
405+
burn_time=3.9,
406+
dry_mass=0,
407+
dry_inertia=(0, 0, 0),
408+
center_of_dry_mass_position=cdm_position,
409+
nozzle_position=nozzle_position,
410+
grain_number=5,
411+
grain_density=1815,
412+
nozzle_radius=33 / 1000,
413+
throat_radius=11 / 1000,
414+
grain_separation=5 / 1000,
415+
grain_outer_radius=33 / 1000,
416+
grain_initial_height=120 / 1000,
417+
grains_center_of_mass_position=grain_cm_position,
418+
grain_initial_inner_radius=15 / 1000,
419+
interpolation_method="linear",
420+
coordinate_system_orientation=coord_direction,
421+
)
422+
calisto = calisto_motorless
423+
calisto.add_motor(example_motor, position=motor_position)
424+
425+
calculated_motor_cdm = calisto.motor_center_of_dry_mass_position
426+
calculated_motor_cpp = calisto.center_of_propellant_position
427+
428+
assert pytest.approx(expected_motor_cdm) == calculated_motor_cdm
429+
assert pytest.approx(expected_motor_cpp) == calculated_motor_cpp(0)
430+
431+
382432
def test_add_cm_eccentricity_assert_properties_set(calisto):
383433
calisto.add_cm_eccentricity(x=4, y=5)
384434

0 commit comments

Comments
 (0)