initialer commit
This commit is contained in:
1 parent
74776ef485
commit
a3095c2df9
18 files changed
+1073
No files matched your search
@@ -0,0 +1,65 @@
|
||||
"""Tests für rot_2D und rot_3D."""
|
||||
|
||||
import math
|
||||
|
||||
import pytest
|
||||
|
||||
from matrixmania import matmul, rot_2D, rot_3D, transpose
|
||||
|
||||
|
||||
def rotate(matrix: list[list[float]], point: list[float]) -> list[float]:
|
||||
"""Dreht einen Punkt mit einer Rotationsmatrix und gibt ihn als Liste zurück."""
|
||||
result = matmul(matrix, transpose([point]))
|
||||
return [row[0] for row in result]
|
||||
|
||||
|
||||
def test_rot_2D_90_degrees():
|
||||
# Arrange
|
||||
point = [1, 0]
|
||||
# Act
|
||||
rotated = rotate(rot_2D(math.pi / 2), point)
|
||||
# Assert
|
||||
assert rotated == pytest.approx([0, 1])
|
||||
|
||||
|
||||
def test_rot_2D_zero_angle_is_identity():
|
||||
# Arrange
|
||||
angle = 0
|
||||
# Act
|
||||
matrix = rot_2D(angle)
|
||||
# Assert
|
||||
assert matrix == [[1, 0], [0, 1]]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"axis, point, expected",
|
||||
[
|
||||
("x", [0, 1, 0], [0, 0, 1]),
|
||||
("y", [0, 0, 1], [1, 0, 0]),
|
||||
("z", [1, 0, 0], [0, 1, 0]),
|
||||
],
|
||||
)
|
||||
def test_rot_3D_90_degrees(axis, point, expected):
|
||||
# Arrange
|
||||
angle = math.pi / 2
|
||||
# Act
|
||||
rotated = rotate(rot_3D(angle, axis), point)
|
||||
# Assert
|
||||
assert rotated == pytest.approx(expected)
|
||||
|
||||
|
||||
def test_rot_3D_point_on_axis_stays():
|
||||
# Arrange
|
||||
point = [1, 0, 0]
|
||||
# Act
|
||||
rotated = rotate(rot_3D(1.23, "x"), point)
|
||||
# Assert
|
||||
assert rotated == pytest.approx(point)
|
||||
|
||||
|
||||
def test_rot_3D_invalid_axis_raises():
|
||||
# Arrange
|
||||
axis = "w"
|
||||
# Act & Assert
|
||||
with pytest.raises(ValueError):
|
||||
rot_3D(1.0, axis)
|
||||
Reference in new issue
Block a user