55 lines
1.0 KiB
Python
55 lines
1.0 KiB
Python
import math
|
|
|
|
import pytest
|
|
|
|
from matrixmania.compute import rot_2D, rot_3D
|
|
|
|
|
|
def assert_matrix_close(actual, expected):
|
|
"""Vergleicht zwei Matrizen elementweise mit Toleranz."""
|
|
assert len(actual) == len(expected)
|
|
for row_a, row_e in zip(actual, expected):
|
|
assert row_a == pytest.approx(row_e, abs=1e-9)
|
|
|
|
|
|
# ---------- rot_2D ----------
|
|
|
|
def test_rot_2D_90_degree():
|
|
# Arrange
|
|
angle = math.pi / 2
|
|
expected = [[0, -1],
|
|
[1, 0]]
|
|
|
|
# Act
|
|
result = rot_2D(angle)
|
|
|
|
# Assert
|
|
assert_matrix_close(result, expected)
|
|
|
|
|
|
# ---------- rot_3D ----------
|
|
|
|
def test_rot_3D_90_degree_z():
|
|
# Arrange
|
|
angle = math.pi / 2
|
|
axis = "z"
|
|
expected = [[0, -1, 0],
|
|
[1, 0, 0],
|
|
[0, 0, 1]]
|
|
|
|
# Act
|
|
result = rot_3D(angle, axis)
|
|
|
|
# Assert
|
|
assert_matrix_close(result, expected)
|
|
|
|
|
|
def test_rot_3D_invalid_axis():
|
|
# Arrange
|
|
angle = 1.0
|
|
axis = "w"
|
|
|
|
# Act + Assert
|
|
with pytest.raises(ValueError):
|
|
rot_3D(angle, axis)
|