Paketstruktur, rot_3D, Projektionen und pytest-Tests
- compute.py nach src/matrixmania verschoben, __init__.py exportiert die Funktionen - rot_3D, project_ortho und project_perspective ergänzt - Tests in test/test_matrixmania (test_rot.py, test_projection.py) - pyproject.toml: dev-Abhängigkeiten und pytest-pythonpath Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
892ec5e2c9
commit
7b8c76c554
9 files changed
+450
-3
No files matched your search
@@ -0,0 +1,91 @@
|
||||
"""Tests für rot_2D und rot_3D."""
|
||||
|
||||
import math
|
||||
|
||||
import pytest
|
||||
|
||||
from matrixmania import matmul, rot_2D, rot_3D
|
||||
|
||||
|
||||
def test_rot_2D_zero_angle_is_identity() -> None:
|
||||
"""Bei 0 Grad ist die Rotationsmatrix die Einheitsmatrix."""
|
||||
# Arrange
|
||||
angle = 0.0
|
||||
|
||||
# Act
|
||||
result = rot_2D(angle)
|
||||
|
||||
# Assert
|
||||
assert result == [[1, 0], [0, 1]]
|
||||
|
||||
|
||||
def test_rot_2D_quarter_turn_moves_x_axis_to_y_axis() -> None:
|
||||
"""Eine Drehung um 90 Grad bringt (1, 0) nach (0, 1)."""
|
||||
# Arrange
|
||||
point = [[1], [0]]
|
||||
|
||||
# Act
|
||||
rotated = matmul(rot_2D(math.pi / 2), point)
|
||||
|
||||
# Assert
|
||||
assert rotated[0][0] == pytest.approx(0, abs=1e-9)
|
||||
assert rotated[1][0] == pytest.approx(1)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("axis", ["x", "y", "z"])
|
||||
def test_rot_3D_zero_angle_is_identity(axis: str) -> None:
|
||||
"""Bei 0 Grad ist die Rotationsmatrix für jede Achse die Einheitsmatrix."""
|
||||
# Arrange
|
||||
identity = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
|
||||
|
||||
# Act
|
||||
result = rot_3D(0.0, axis)
|
||||
|
||||
# Assert
|
||||
assert result == identity
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("axis", "point", "expected"),
|
||||
[
|
||||
("x", [[0], [1], [0]], [[0], [0], [1]]), # y-Achse -> z-Achse
|
||||
("y", [[0], [0], [1]], [[1], [0], [0]]), # z-Achse -> x-Achse
|
||||
("z", [[1], [0], [0]], [[0], [1], [0]]), # x-Achse -> y-Achse
|
||||
],
|
||||
)
|
||||
def test_rot_3D_quarter_turn(
|
||||
axis: str, point: list[list[float]], expected: list[list[float]]
|
||||
) -> None:
|
||||
"""Eine Drehung um 90 Grad dreht die Achsen wie erwartet weiter."""
|
||||
# Arrange
|
||||
rotation = rot_3D(math.pi / 2, axis)
|
||||
|
||||
# Act
|
||||
result = matmul(rotation, point)
|
||||
|
||||
# Assert
|
||||
for row, expected_row in zip(result, expected, strict=True):
|
||||
assert row[0] == pytest.approx(expected_row[0], abs=1e-9)
|
||||
|
||||
|
||||
def test_rot_3D_point_on_axis_stays_unchanged() -> None:
|
||||
"""Ein Punkt auf der Drehachse bleibt bei der Drehung liegen."""
|
||||
# Arrange
|
||||
point_on_x_axis = [[2], [0], [0]]
|
||||
|
||||
# Act
|
||||
result = matmul(rot_3D(1.2, "x"), point_on_x_axis)
|
||||
|
||||
# Assert
|
||||
assert result == [[2], [0], [0]]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("axis", ["a", "X", "", "xy"])
|
||||
def test_rot_3D_invalid_axis_raises_value_error(axis: str) -> None:
|
||||
"""Ungültige Achsen führen zu einem ValueError."""
|
||||
# Arrange
|
||||
angle = 1.0
|
||||
|
||||
# Act / Assert
|
||||
with pytest.raises(ValueError):
|
||||
rot_3D(angle, axis)
|
||||
Reference in new issue
Block a user