Orthogonale Projektion und 3D_rot mit Tests ergänzt
This commit is contained in:
1 parent
b5f5a154ba
commit
6ededbc4c2
7 files changed
+214
-5
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,26 @@
|
||||
from matrixmania import project_ortho
|
||||
|
||||
|
||||
def test_project_ortho_without_scale():
|
||||
# Arrange
|
||||
point = (1.0, 2.0, 3.0)
|
||||
expected = (1.0, 2.0)
|
||||
|
||||
# Act
|
||||
result = project_ortho(point)
|
||||
|
||||
# Assert
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_project_ortho_with_scale_100():
|
||||
# Arrange
|
||||
point = (1.0, 2.0, 3.0)
|
||||
scale = 100
|
||||
expected = (100.0, 200.0)
|
||||
|
||||
# Act
|
||||
result = project_ortho(point, scale=scale)
|
||||
|
||||
# Assert
|
||||
assert result == expected
|
||||
@@ -0,0 +1,98 @@
|
||||
import math
|
||||
|
||||
import pytest
|
||||
|
||||
from matrixmania import matmul, rot_2D, rot_3D
|
||||
|
||||
|
||||
def test_rot_2D_zero_angle_returns_identity():
|
||||
# Arrange
|
||||
angle = 0.0
|
||||
expected = [[1.0, 0.0], [0.0, 1.0]]
|
||||
|
||||
# Act
|
||||
result = rot_2D(angle)
|
||||
|
||||
# Assert
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_rot_2D_rotates_point_by_90_degrees():
|
||||
# Arrange
|
||||
angle = math.radians(90)
|
||||
point = [[1], [0]]
|
||||
expected = [0.0, 1.0]
|
||||
|
||||
# Act
|
||||
result = [row[0] for row in matmul(rot_2D(angle), point)]
|
||||
|
||||
# Assert
|
||||
assert result == pytest.approx(expected, abs=1e-9)
|
||||
|
||||
|
||||
def test_rot_2D_rotates_point_by_180_degrees():
|
||||
# Arrange
|
||||
angle = math.pi
|
||||
point = [[2], [1]]
|
||||
expected = [-2.0, -1.0]
|
||||
|
||||
# Act
|
||||
result = [row[0] for row in matmul(rot_2D(angle), point)]
|
||||
|
||||
# Assert
|
||||
assert result == pytest.approx(expected, abs=1e-9)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("axis", ["x", "y", "z"])
|
||||
def test_rot_3D_zero_angle_returns_identity(axis):
|
||||
# Arrange
|
||||
angle = 0.0
|
||||
expected = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
|
||||
|
||||
# Act
|
||||
result = rot_3D(angle, axis)
|
||||
|
||||
# Assert
|
||||
assert result == expected
|
||||
|
||||
|
||||
@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_rotates_point_by_90_degrees(axis, point, expected):
|
||||
# Arrange
|
||||
angle = math.radians(90)
|
||||
|
||||
# Act
|
||||
result = [row[0] for row in matmul(rot_3D(angle, axis), point)]
|
||||
|
||||
# Assert
|
||||
assert result == pytest.approx(expected, abs=1e-9)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("axis", ["x", "y", "z"])
|
||||
def test_rot_3D_returns_3x3_matrix(axis):
|
||||
# Arrange
|
||||
angle = 1.0
|
||||
|
||||
# Act
|
||||
result = rot_3D(angle, axis)
|
||||
|
||||
# Assert
|
||||
assert len(result) == 3
|
||||
assert all(len(row) == 3 for row in result)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid_axis", ["w", "", "X", "xy"])
|
||||
def test_rot_3D_invalid_axis_raises_value_error(invalid_axis):
|
||||
# Arrange
|
||||
angle = 1.0
|
||||
|
||||
# Act / Assert
|
||||
with pytest.raises(ValueError):
|
||||
rot_3D(angle, invalid_axis)
|
||||
Reference in new issue
Block a user