6 commit praktikum

This commit is contained in:
washingtonta103380 committed 2026-10-21 11:35:04 +02:00
1 parent 521c35f621
commit 883375e3f0
2 files changed
+31 -33

No files matched your search

+3 -1
View File
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4"> <module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="Python 3.13 (PythonProject)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.13 (PythonProject)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
+28 -32
View File
@@ -2,7 +2,7 @@ import math
import pytest import pytest
from matrixmania.compute import matmul, rot_2D, rot_3D, transpose from matrixmania.compute import rot_2D, rot_3D
def assert_matrix_close(actual, expected): def assert_matrix_close(actual, expected):
@@ -14,45 +14,41 @@ def assert_matrix_close(actual, expected):
# ---------- rot_2D ---------- # ---------- rot_2D ----------
def test_rot_2D_zero():
assert_matrix_close(rot_2D(0), [[1, 0], [0, 1]])
def test_rot_2D_90_degree(): def test_rot_2D_90_degree():
assert_matrix_close(rot_2D(math.pi / 2), [[0, -1], [1, 0]]) # Arrange
angle = math.pi / 2
expected = [[0, -1],
[1, 0]]
# Act
result = rot_2D(angle)
def test_rot_2D_invalid_input(): # Assert
with pytest.raises(TypeError): assert_matrix_close(result, expected)
rot_2D("abc")
# ---------- rot_3D ---------- # ---------- rot_3D ----------
@pytest.mark.parametrize("axis", ["x", "y", "z"]) def test_rot_3D_90_degree_z():
def test_rot_3D_zero_is_identity(axis): # Arrange
assert_matrix_close(rot_3D(0, axis), [[1, 0, 0], [0, 1, 0], [0, 0, 1]]) angle = math.pi / 2
axis = "z"
expected = [[0, -1, 0],
[1, 0, 0],
[0, 0, 1]]
# Act
result = rot_3D(angle, axis)
# Assert
assert_matrix_close(result, expected)
@pytest.mark.parametrize( def test_rot_3D_invalid_axis():
"axis, expected", # Arrange
[ angle = 1.0
("x", [[1, 0, 0], [0, 0, -1], [0, 1, 0]]), axis = "w"
("y", [[0, 0, 1], [0, 1, 0], [-1, 0, 0]]),
("z", [[0, -1, 0], [1, 0, 0], [0, 0, 1]]),
],
)
def test_rot_3D_90_degree(axis, expected):
assert_matrix_close(rot_3D(math.pi / 2, axis), expected)
# Act + Assert
@pytest.mark.parametrize("axis", ["x", "y", "z"])
def test_rot_3D_is_orthogonal(axis):
r = rot_3D(1.0, axis)
assert_matrix_close(matmul(r, transpose(r)), [[1, 0, 0], [0, 1, 0], [0, 0, 1]])
@pytest.mark.parametrize("axis", ["w", "X", "", "xy"])
def test_rot_3D_invalid_axis(axis):
with pytest.raises(ValueError): with pytest.raises(ValueError):
rot_3D(1.0, axis) rot_3D(angle, axis)