import math import pytest from src.MatrixMania.compute import rot_2d, rot_3d # --- Tests für rot_2d --- def test_rot_2d_vector_valid(): # 90° Drehung von [1, 0] um den Ursprung -> [0, 1] res = rot_2d([1.0, 0.0], math.pi / 2) assert math.isclose(res[0], 0.0, abs_tol=1e-9) assert math.isclose(res[1], 1.0, abs_tol=1e-9) def test_rot_2d_matrix_valid(): # 90° Drehung im Uhrzeigersinn m = [[1, 2], [3, 4]] assert rot_2d(m) == [[3, 1], [4, 2]] def test_rot_2d_invalid_vector(): # Vektor mit ungültiger Länge muss ValueError werfen with pytest.raises(ValueError): rot_2d([1.0, 2.0, 3.0], math.pi) # --- Tests für rot_3D --- def test_rot_3d_identity(): # Bei Winkel 0 müssen alle Achsen die Einheitsmatrix liefern eye = [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], ] for axis in ["x", "y", "z"]: res = rot_3d(0.0, axis) for r in range(3): for c in range(3): assert math.isclose(res[r][c], eye[r][c], abs_tol=1e-9) def test_rot_3d_x_axis(): # 90° um x-Achse res = rot_3d(math.pi / 2, "x") expected = [ [1.0, 0.0, 0.0], [0.0, 0.0, -1.0], [0.0, 1.0, 0.0], ] for r in range(3): for c in range(3): assert math.isclose(res[r][c], expected[r][c], abs_tol=1e-9) def test_rot_3d_y_axis(): # 90° um y-Achse res = rot_3d(math.pi / 2, "y") expected = [ [0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [-1.0, 0.0, 0.0], ] for r in range(3): for c in range(3): assert math.isclose(res[r][c], expected[r][c], abs_tol=1e-9) def test_rot_3d_z_axis(): # 90° um z-Achse res = rot_3d(math.pi / 2, "z") expected = [ [0.0, -1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0], ] for r in range(3): for c in range(3): assert math.isclose(res[r][c], expected[r][c], abs_tol=1e-9) def test_rot_3d_invalid_axis(): # Ungültige Achsenbezeichnung muss ValueError werfen with pytest.raises(ValueError): rot_3d(math.pi / 2, "w") with pytest.raises(ValueError): rot_3d(math.pi / 2, "1")