rot_3D mit Tests für rot_2D und rot_3D
This commit is contained in:
1 parent
d633de0293
commit
bc2c069bda
2 files changed
+96
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import math
|
||||
|
||||
import pytest
|
||||
|
||||
from compute import rot_2D, rot_3D
|
||||
|
||||
|
||||
def flatten(matrix: list[list[float]]) -> list[float]:
|
||||
return [value for row in matrix for value in row]
|
||||
|
||||
|
||||
def test_rot_2d_zero_angle_is_identity():
|
||||
# Arrange
|
||||
angle = 0.0
|
||||
expected = [[1.0, 0.0], [0.0, 1.0]]
|
||||
|
||||
# Act
|
||||
result = rot_2D(angle)
|
||||
|
||||
# Assert
|
||||
assert flatten(result) == pytest.approx(flatten(expected))
|
||||
|
||||
|
||||
def test_rot_2d_quarter_turn():
|
||||
# Arrange
|
||||
angle = math.pi / 2
|
||||
expected = [[0.0, -1.0], [1.0, 0.0]]
|
||||
|
||||
# Act
|
||||
result = rot_2D(angle)
|
||||
|
||||
# Assert
|
||||
assert flatten(result) == pytest.approx(flatten(expected), abs=1e-9)
|
||||
|
||||
|
||||
def test_rot_3d_x_axis_quarter_turn():
|
||||
# Arrange
|
||||
angle = math.pi / 2
|
||||
expected = [[1.0, 0.0, 0.0], [0.0, 0.0, -1.0], [0.0, 1.0, 0.0]]
|
||||
|
||||
# Act
|
||||
result = rot_3D(angle, "x")
|
||||
|
||||
# Assert
|
||||
assert flatten(result) == pytest.approx(flatten(expected), abs=1e-9)
|
||||
|
||||
|
||||
def test_rot_3d_z_axis_zero_angle_is_identity():
|
||||
# Arrange
|
||||
expected = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
|
||||
|
||||
# Act
|
||||
result = rot_3D(0.0, "z")
|
||||
|
||||
# Assert
|
||||
assert flatten(result) == pytest.approx(flatten(expected))
|
||||
|
||||
|
||||
def test_rot_3d_invalid_axis_raises_value_error():
|
||||
# Arrange
|
||||
invalid_axis = "w"
|
||||
|
||||
# Act / Assert
|
||||
with pytest.raises(ValueError):
|
||||
rot_3D(1.0, invalid_axis)
|
||||
Reference in new issue
Block a user