Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/unit/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
haversine,
inverted_haversine,
mercator_to_wgs84,
normalize_quaternions,
quaternions_to_nutation,
quaternions_to_precession,
quaternions_to_spin,
tuple_handler,
)

Expand Down Expand Up @@ -41,6 +45,28 @@ def test_euler_to_quaternions(angles, expected_quaternions):
assert round(q3, 7) == expected_quaternions[3]


def test_quaternions_to_euler_angles_support_flight_arrays():
quaternions = np.array(
[
(0.5, -(0.5**0.5), 0.0, 0.5),
(0.5, -0.5, -0.5, 0.5),
]
)
e0, e1, e2, e3 = quaternions.T

assert quaternions_to_precession(e0, e1, e2, e3) == pytest.approx([45, 90])
assert quaternions_to_nutation(e1, e2) == pytest.approx([-90, -90])
assert quaternions_to_spin(e0, e1, e2, e3) == pytest.approx([45, 0])


def test_normalize_quaternions_handles_scaled_and_zero_inputs():
normalized = normalize_quaternions((1, 2, 3, 4))

assert normalized == pytest.approx(np.array([1, 2, 3, 4]) / np.sqrt(30))
assert np.linalg.norm(normalized) == pytest.approx(1)
assert normalize_quaternions((0, 0, 0, 0)) == (1, 0, 0, 0)


def test_calculate_cubic_hermite_coefficients():
"""Test the calculate_cubic_hermite_coefficients method of the Function class."""
# Function: f(x) = x**3 + 2x**2 -1 ; derivative: f'(x) = 3x**2 + 4x
Expand Down
Loading