48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
import pytest
|
|
from matrixmania.compute import rot_2D, rot_3D
|
|
|
|
|
|
# --- Tests für Rotationen (2D & 3D) ---
|
|
def test_rot_2D():
|
|
# 90 Grad Rotation in 2D: (1, 0) -> (0, 1)
|
|
# Matrix sollte [[0, -1], [1, 0]] sein (cos(90)=0, sin(90)=1)
|
|
result = rot_2D(90)
|
|
|
|
# Wir nutzen pytest.approx für Float-Vergleiche, da 0.00000000001 != 0 ist
|
|
assert result[0][0] == pytest.approx(0.0) # cos
|
|
assert result[0][1] == pytest.approx(-1.0) # -sin
|
|
assert result[1][0] == pytest.approx(1.0) # sin
|
|
assert result[1][1] == pytest.approx(0.0) # cos
|
|
|
|
|
|
def test_rot_3D_x_axis():
|
|
# 90 Grad um X-Achse
|
|
# Erwartet:
|
|
# 1 0 0
|
|
# 0 0 -1
|
|
# 0 1 0
|
|
result = rot_3D(90, 'x')
|
|
|
|
assert result[0] == [1.0, 0.0, 0.0] # X-Achse bleibt stabil
|
|
assert result[1][1] == pytest.approx(0.0)
|
|
assert result[1][2] == pytest.approx(-1.0)
|
|
assert result[2][1] == pytest.approx(1.0)
|
|
|
|
|
|
def test_rot_3D_z_axis():
|
|
# 180 Grad um Z-Achse
|
|
# Erwartet:
|
|
# -1 0 0
|
|
# 0 -1 0
|
|
# 0 0 1
|
|
result = rot_3D(180, 'z')
|
|
|
|
assert result[0][0] == pytest.approx(-1.0)
|
|
assert result[1][1] == pytest.approx(-1.0)
|
|
assert result[2][2] == pytest.approx(1.0)
|
|
|
|
|
|
def test_rot_3D_invalid_input():
|
|
# Testet, ob Fehler geworfen wird bei falscher Achse
|
|
with pytest.raises(ValueError):
|
|
rot_3D(90, 'q') # 'q' gibt es nicht |