diff --git a/pyproject.toml b/pyproject.toml index 8ad05c1..6083f2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,4 +13,9 @@ dependencies = ["tabulate"] requires = ["hatchling"] build-backend = "hatchling.build" [tool.hatch.build.targets.wheel] -packages = ["matrixmania"] \ No newline at end of file +packages = ["matrixmania"] + +[tool.pytest.ini_options] +pythonpath = [ + "." +] diff --git a/tests/test_matmul.py b/tests/test_matmul.py new file mode 100644 index 0000000..d29fc3b --- /dev/null +++ b/tests/test_matmul.py @@ -0,0 +1,14 @@ +from matrixmania.compute import matmul, transpose +import pytest + +def test_matmul_basic(): + a = [[1, 2], [3, 4]] + b = [[2, 0], [1, 2]] + expected = [[4, 4], [10, 8]] + assert matmul(a, b) == expected + +def test_matmul_invalid_dimensions(): + a = [[1, 2, 3]] + b = [[1, 2], [3, 4]] + with pytest.raises(ValueError): + matmul(a, b) diff --git a/tests/test_rot.py b/tests/test_rot.py new file mode 100644 index 0000000..a894443 --- /dev/null +++ b/tests/test_rot.py @@ -0,0 +1,20 @@ +from matrixmania.compute import rot_2D +import math + +def test_rot_2D_identity(): + """Rotation by 0 radians should return identity matrix""" + result = rot_2D(0) + expected = [[1, 0], [0, 1]] + assert all(abs(result[i][j] - expected[i][j]) < 1e-9 for i in range(2) for j in range(2)) + +def test_rot_2D_90_degrees(): + """Rotation by 90° (pi/2 radians)""" + result = rot_2D(math.pi / 2) + expected = [[0, -1], [1, 0]] + assert all(abs(result[i][j] - expected[i][j]) < 1e-9 for i in range(2) for j in range(2)) + +def test_rot_2D_180_degrees(): + """Rotation by 180° (pi radians)""" + result = rot_2D(math.pi) + expected = [[-1, 0], [0, -1]] + assert all(abs(result[i][j] - expected[i][j]) < 1e-9 for i in range(2) for j in range(2))