33 lines
848 B
Python
33 lines
848 B
Python
"""Unit test della normalizzazione quaternion server-side."""
|
|
from __future__ import annotations
|
|
|
|
import math
|
|
import numpy as np
|
|
import pytest
|
|
|
|
from presa_mano.geometry import normalize_quaternion
|
|
|
|
|
|
def test_already_normalized_is_unchanged():
|
|
q = [0.0, 0.0, 0.0, 1.0]
|
|
out = normalize_quaternion(q)
|
|
assert np.allclose(out, q)
|
|
|
|
|
|
def test_not_normalized_gets_normalized_to_unit_length():
|
|
# scala 2.0
|
|
q = [0.0, 0.0, 0.0, 2.0]
|
|
out = normalize_quaternion(q)
|
|
norm = math.sqrt(sum(x*x for x in out))
|
|
assert abs(norm - 1.0) < 1e-9
|
|
|
|
|
|
def test_degenerate_zero_quat_raises():
|
|
with pytest.raises(ValueError, match="degenerate"):
|
|
normalize_quaternion([0.0, 0.0, 0.0, 0.0])
|
|
|
|
|
|
def test_near_zero_quat_raises():
|
|
with pytest.raises(ValueError, match="degenerate"):
|
|
normalize_quaternion([1e-9, 0.0, 0.0, 1e-9])
|