56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
import math
|
|
import pytest
|
|
|
|
from matrixmania import rot_2D, rot_3D
|
|
|
|
def test_rot2D(): # gibt Rotationsmatrix für 90 grad
|
|
# Arrange
|
|
theta = math.pi / 2 # 90 Grad in Radiant
|
|
erwartet = [[0.0, -1.0], [1.0, 0.0]]
|
|
|
|
# Act
|
|
ergebnis = rot_2D(theta)
|
|
|
|
# Assert
|
|
assert len(ergebnis) == 2
|
|
assert all(len(zeile) == 2 for zeile in ergebnis)
|
|
for zeile_ist, zeile_soll in zip(ergebnis, erwartet):
|
|
assert zeile_ist == pytest.approx(zeile_soll, abs=1e-9)
|
|
|
|
@pytest.mark.parametrize(
|
|
"axis, erwartet",
|
|
[
|
|
("x", [[1.0, 0.0, 0.0],
|
|
[0.0, 0.0, -1.0],
|
|
[0.0, 1.0, 0.0]]),
|
|
("y", [[ 0.0, 0.0, 1.0],
|
|
[ 0.0, 1.0, 0.0],
|
|
[-1.0, 0.0, 0.0]]),
|
|
("z", [[0.0, -1.0, 0.0],
|
|
[1.0, 0.0, 0.0],
|
|
[0.0, 0.0, 1.0]]),
|
|
],
|
|
)
|
|
def test_rot3D(axis, erwartet): # bei 90 Grad Rotation um jede Achse
|
|
# Arrange
|
|
angle = math.pi / 2 # 90 Grad in Radiant
|
|
|
|
# Act
|
|
ergebnis = rot_3D(angle, axis)
|
|
|
|
# Assert
|
|
assert len(ergebnis) == 3
|
|
assert all(len(zeile) == 3 for zeile in ergebnis)
|
|
for zeile_ist, zeile_soll in zip(ergebnis, erwartet):
|
|
assert zeile_ist == pytest.approx(zeile_soll, abs=1e-9)
|
|
|
|
|
|
def test_rot3D_ungueltige_achse(): # wirft ValueError bei ungültiger Achse
|
|
# Arrange
|
|
angle = math.pi / 2
|
|
axis = "w"
|
|
|
|
# Act & Assert
|
|
with pytest.raises(ValueError, match="Unsupported rotation axis"):
|
|
rot_3D(angle, axis)
|