"""Executable spec drafted by the SICurator spec engine.

Generated from the scientific computing skill pack.
"""

# risk: 0 (low)
# - checks come from the scientific computing skill pack

from __future__ import annotations

import math

from hypothesis import given, settings, strategies as st

from orbitlab.integrator import step, total_energy

# sicurator-target: kind=conservation step=orbitlab.integrator.step energy=orbitlab.integrator.total_energy
@settings(max_examples=8, deadline=None, derandomize=True)
@given(
    st.floats(min_value=0.5, max_value=1.0, allow_nan=False, allow_infinity=False),
    st.floats(min_value=-1.0, max_value=1.0, allow_nan=False, allow_infinity=False),
)
def test_energy_conservation(x, v):
    """Total energy must not drift over a fixed horizon."""
    state = (x, v)
    initial = total_energy(state)
    for _ in range(80):
        state = step(state, 0.05)
    final = total_energy(state)
    assert abs(final - initial) <= 1e-3 * max(abs(initial), 1.0)
