Skip to content

Commit d4e90fc

Browse files
committed
TST: implement testing for discretized encoding.
1 parent 99591c7 commit d4e90fc

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tests/integration/test_encoding.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,36 @@ def test_rocket_encoder(rocket_name, request):
228228
rocket_to_encode.static_margin(sample_times),
229229
rocket_loaded.static_margin(sample_times),
230230
)
231+
232+
233+
@pytest.mark.parametrize("rocket_name", ["calisto_robust"])
234+
def test_encoder_discretize(rocket_name, request):
235+
"""Test encoding the total mass of``rocketpy.Rocket`` with
236+
discretized encoding.
237+
238+
Parameters
239+
----------
240+
rocket_name : str
241+
Name of the rocket fixture to encode.
242+
request : pytest.FixtureRequest
243+
Pytest request object.
244+
"""
245+
rocket_to_encode = request.getfixturevalue(rocket_name)
246+
247+
json_encoded = json.dumps(
248+
rocket_to_encode, cls=RocketPyEncoder, discretize=True, include_outputs=True
249+
)
250+
251+
mass_loaded = json.loads(
252+
json.dumps(json.loads(json_encoded)["total_mass"]), cls=RocketPyDecoder
253+
)
254+
255+
sample_times = np.linspace(*rocket_to_encode.motor.burn_time, 100)
256+
257+
np.testing.assert_allclose(
258+
mass_loaded(sample_times),
259+
rocket_to_encode.total_mass(sample_times),
260+
rtol=1e-3,
261+
atol=1e-1,
262+
)
263+
assert isinstance(mass_loaded.source, np.ndarray)

0 commit comments

Comments
 (0)