From 4a838bfdc8c629b08e8eb4280e8698bf89fd0f5e Mon Sep 17 00:00:00 2001 From: Phexi Date: Thu, 22 Oct 2026 15:21:29 +0200 Subject: [PATCH] add rotation tests --- pyproject.toml | 5 ++++- compute.py => src/compute.py | 6 +++++- test/test_compute.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) rename compute.py => src/compute.py (95%) create mode 100644 test/test_compute.py diff --git a/pyproject.toml b/pyproject.toml index 0a10d49..8a52cbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,7 @@ [project] name = "matrixmania" version = "0.1.0" -dependencies = ["tabulate", "ruff", "pytest-cov"] \ No newline at end of file +dependencies = ["tabulate", "ruff", "pytest-cov"] + +[tool.pytest.ini_options] +pythonpath = "src" \ No newline at end of file diff --git a/compute.py b/src/compute.py similarity index 95% rename from compute.py rename to src/compute.py index 0f42a61..6a14156 100644 --- a/compute.py +++ b/src/compute.py @@ -76,7 +76,7 @@ def matmul( -def rot_2D(matrix: list[list[float]], angle:int) -> list[list[float]]: +def rot_2D(matrix: list[list[float]], angle:float) -> list[list[float]]: """Apply a rotation matrix to a base matrix. Parameters @@ -140,6 +140,10 @@ def rot_3D(angle:float, axis: str) -> list[list[float]]: return [row_1, row_2, row_3] +def project_ortho(point: tuple[float, float, float], scale: float = 1) -> tuple[float, float, float]: + return + + def transpose(matrix: list[list[float]]) -> list[list[float]]: """Return the transpose of a 2‑D list. diff --git a/test/test_compute.py b/test/test_compute.py new file mode 100644 index 0000000..79c2fd6 --- /dev/null +++ b/test/test_compute.py @@ -0,0 +1,33 @@ +import math + +from src.compute import rot_2D, rot_3D + +def test_get_2D_rotation_matrix(): + + #Arrange + mat = [[0], [0]] + angle = math.pi + expected_matrix = [[math.cos(math.pi), -math.sin(math.pi)], [math.sin(math.pi), math.cos(math.pi)]] + + #Act + rot = rot_2D(mat, angle) + + #Assert + assert rot == expected_matrix + +def test_get_3D_rotation_matrix(): + + #Arrange + angle = math.pi + axis = "x" + expected_matrix = [ + [1, 0, 0], + [0, math.cos(math.pi), -math.sin(math.pi)], + [0, math.sin(math.pi), math.cos(math.pi)]] + + #Act + rot = rot_3D(angle, axis) + + #Assert + assert rot == expected_matrix +