Add orthogonal projection and tests

This commit is contained in:
Amalia Sucipto committed 2026-10-28 23:00:08 +01:00
1 parent 17eff74d0c
commit 4931d5e7dc
4 files changed
+46 -2

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
from compute import project_ortho
def test_project_ortho_without_scaling() -> None:
"""Test orthogonal projection without scaling."""
# Arrange
point = (1.0, 2.0, 3.0)
expected = (1.0, 2.0)
# Act
result = project_ortho(point)
# Assert
assert result == expected
def test_project_ortho_with_scaling() -> None:
"""Test orthogonal projection with a scale factor of 100."""
# Arrange
point = (1.0, 2.0, 3.0)
scale = 100
expected = (100.0, 200.0)
# Act
result = project_ortho(point, scale)
# Assert
assert result == expected
+43
View File
@@ -0,0 +1,43 @@
from math import pi
import pytest
from compute import rot_2D, rot_3D
def test_rot_2D() -> None:
"""Test a 90-degree rotation matrix in 2D."""
# Arrange
angle = pi / 2
expected = [
[0.0, -1.0],
[1.0, 0.0],
]
# Act
result = rot_2D(angle)
# Assert
for i in range(2):
for j in range(2):
assert result[i][j] == pytest.approx(expected[i][j])
def test_rot_3D() -> None:
"""Test a 90-degree rotation matrix around the z-axis."""
# Arrange
angle = pi / 2
axis = "z"
expected = [
[0.0, -1.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 0.0, 1.0],
]
# Act
result = rot_3D(angle, axis)
# Assert
for i in range(3):
for j in range(3):
assert result[i][j] == pytest.approx(expected[i][j])