"""Unit-Tests für die Rotationsfunktionen in compute.py.""" import math import pytest from matrixmania import rot_2d, rot_3d def test_rot_2d_zero_angle() -> None: """Testet die 2D-Rotation um 0 Radiant (Einheitsmatrix).""" # Arrange angle = 0.0 # Act result = rot_2d(angle) # Assert assert math.isclose(result[0][0], 1.0, abs_tol=1e-9) assert math.isclose(result[0][1], 0.0, abs_tol=1e-9) assert math.isclose(result[1][0], 0.0, abs_tol=1e-9) assert math.isclose(result[1][1], 1.0, abs_tol=1e-9) def test_rot_2d_pi_half() -> None: """Testet die 2D-Rotation um pi / 2 Radiant (90 Grad).""" # Arrange angle = math.pi / 2 # Act result = rot_2d(angle) # Assert assert math.isclose(result[0][0], 0.0, abs_tol=1e-9) assert math.isclose(result[0][1], -1.0, abs_tol=1e-9) assert math.isclose(result[1][0], 1.0, abs_tol=1e-9) assert math.isclose(result[1][1], 0.0, abs_tol=1e-9) def test_rot_2d_pi() -> None: """Testet die 2D-Rotation um pi Radiant (180 Grad).""" # Arrange angle = math.pi # Act result = rot_2d(angle) # Assert assert math.isclose(result[0][0], -1.0, abs_tol=1e-9) assert math.isclose(result[0][1], 0.0, abs_tol=1e-9) assert math.isclose(result[1][0], 0.0, abs_tol=1e-9) assert math.isclose(result[1][1], -1.0, abs_tol=1e-9) def test_rot_2d_negative_angle() -> None: """Testet die 2D-Rotation mit einem negativen Winkel (-pi / 2).""" # Arrange angle = -math.pi / 2 # Act result = rot_2d(angle) # Assert assert math.isclose(result[0][0], 0.0, abs_tol=1e-9) assert math.isclose(result[0][1], 1.0, abs_tol=1e-9) assert math.isclose(result[1][0], -1.0, abs_tol=1e-9) assert math.isclose(result[1][1], 0.0, abs_tol=1e-9) def test_rot_3d_x_axis_zero() -> None: """Testet die 3D-Rotation um die x-Achse um 0 Radiant.""" # Arrange angle = 0.0 axis = "x" # Act result = rot_3d(angle, axis) # Assert expected = [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], ] for row in range(3): for col in range(3): assert math.isclose(result[row][col], expected[row][col], abs_tol=1e-9) def test_rot_3d_x_axis_pi_half() -> None: """Testet die 3D-Rotation um die x-Achse um pi / 2 Radiant.""" # Arrange angle = math.pi / 2 axis = "x" # Act result = rot_3d(angle, axis) # Assert expected = [ [1.0, 0.0, 0.0], [0.0, 0.0, -1.0], [0.0, 1.0, 0.0], ] for row in range(3): for col in range(3): assert math.isclose(result[row][col], expected[row][col], abs_tol=1e-9) def test_rot_3d_y_axis_zero() -> None: """Testet die 3D-Rotation um die y-Achse um 0 Radiant.""" # Arrange angle = 0.0 axis = "y" # Act result = rot_3d(angle, axis) # Assert expected = [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], ] for row in range(3): for col in range(3): assert math.isclose(result[row][col], expected[row][col], abs_tol=1e-9) def test_rot_3d_y_axis_pi_half() -> None: """Testet die 3D-Rotation um die y-Achse um pi / 2 Radiant.""" # Arrange angle = math.pi / 2 axis = "y" # Act result = rot_3d(angle, axis) # Assert expected = [ [0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [-1.0, 0.0, 0.0], ] for row in range(3): for col in range(3): assert math.isclose(result[row][col], expected[row][col], abs_tol=1e-9) def test_rot_3d_z_axis_zero() -> None: """Testet die 3D-Rotation um die z-Achse um 0 Radiant.""" # Arrange angle = 0.0 axis = "z" # Act result = rot_3d(angle, axis) # Assert expected = [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], ] for row in range(3): for col in range(3): assert math.isclose(result[row][col], expected[row][col], abs_tol=1e-9) def test_rot_3d_z_axis_pi_half() -> None: """Testet die 3D-Rotation um die z-Achse um pi / 2 Radiant.""" # Arrange angle = math.pi / 2 axis = "z" # Act result = rot_3d(angle, axis) # Assert expected = [ [0.0, -1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0], ] for row in range(3): for col in range(3): assert math.isclose(result[row][col], expected[row][col], abs_tol=1e-9) @pytest.mark.parametrize("invalid_axis", ["w", "123", "", "X", "Y", "Z"]) def test_rot_3d_invalid_axis(invalid_axis: str) -> None: """Testet, dass ungültige Achsen einen ValueError auslösen.""" # Arrange angle = 1.0 # Act & Assert with pytest.raises(ValueError, match="Ungültige Achse"): rot_3d(angle, invalid_axis)