|
| 1 | +import pytest |
| 2 | +import numpy as np |
| 3 | +from rocketpy.simulation.flight import Flight |
| 4 | +from rocketpy.rocket.rocket import PointMassRocket |
| 5 | +from rocketpy.motors.point_mass_motor import PointMassMotor |
| 6 | + |
| 7 | +class DummyEnv: |
| 8 | + # Minimal stub, adapt with real Environment in your RocketPy setup |
| 9 | + windvelocityx = windvelocityy = speedofsound = pressure = density = dynamicviscosity = lambda self: 0 |
| 10 | + gravity = lambda self: 9.81 |
| 11 | + elevation = 0 |
| 12 | + def __getattr__(self, name): |
| 13 | + return lambda *a, **k: 0 |
| 14 | + |
| 15 | +def make_simple_3dof_components(): |
| 16 | + env = DummyEnv() |
| 17 | + motor = PointMassMotor(10, dry_mass=1.0, propellant_initial_mass=0.5, burn_time=2.2) |
| 18 | + rocket = PointMassRocket(0.05, 2.0, 0.1, 0.5, 0.6) |
| 19 | + rocket.addmotor(motor, 0) |
| 20 | + return env, rocket |
| 21 | + |
| 22 | +def test_3dof_simulation_mode_autoset(): |
| 23 | + env, rocket = make_simple_3dof_components() |
| 24 | + flight = Flight(rocket=rocket, environment=env, rail_length=1, simulation_mode="3 DOF") |
| 25 | + assert flight.simulation_mode == "3 DOF" |
| 26 | + |
| 27 | +def test_3dof_simulation_mode_warning(monkeypatch): |
| 28 | + env, rocket = make_simple_3dof_components() |
| 29 | + monkeypatch.setattr("warnings.warn", lambda *a, **k: None) |
| 30 | + f = Flight(rocket=rocket, environment=env, rail_length=1, simulation_mode="6 DOF") |
| 31 | + assert f.simulation_mode == "3 DOF" |
| 32 | + |
| 33 | +def test_3dof_equations_of_motion_functions(): |
| 34 | + env, rocket = make_simple_3dof_components() |
| 35 | + flight = Flight(rocket=rocket, environment=env, rail_length=1, simulation_mode="3 DOF") |
| 36 | + u = [0]*13 # Proper size for generalized state for 3/6 DOF probably |
| 37 | + result = flight.udotgeneralized3dof(0, u) |
| 38 | + assert isinstance(result, list) or isinstance(result, np.ndarray) |
| 39 | + |
| 40 | +def test_invalid_simulation_mode(): |
| 41 | + env, rocket = make_simple_3dof_components() |
| 42 | + with pytest.raises(ValueError): |
| 43 | + Flight(rocket=rocket, environment=env, rail_length=1, simulation_mode="2 DOF") |
0 commit comments