61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
"""Unit-Tests für Projektionen in compute.py."""
|
|
|
|
import math
|
|
|
|
from matrixmania.compute import project_ortho, project_perspective
|
|
|
|
|
|
def test_project_ortho_default_scale() -> None:
|
|
"""Testet die orthogonale Projektion mit Standard-Skalierungsfaktor."""
|
|
# Arrange
|
|
point = (1.0, 2.0, 3.0)
|
|
|
|
# Act
|
|
result = project_ortho(point)
|
|
|
|
# Assert
|
|
assert result == (1.0, 2.0)
|
|
|
|
|
|
def test_project_ortho_scaled() -> None:
|
|
"""Testet die orthogonale Projektion mit einem Skalierungsfaktor von 100."""
|
|
# Arrange
|
|
point = (1.0, 2.0, 3.0)
|
|
scale = 100
|
|
|
|
# Act
|
|
result = project_ortho(point, scale=scale)
|
|
|
|
# Assert
|
|
assert result == (100.0, 200.0)
|
|
|
|
|
|
def test_project_perspective_scale_and_focal_length_one() -> None:
|
|
"""Testet die perspektivische Projektion mit scale=1 und focal_length=1."""
|
|
# Arrange
|
|
point = (1.0, 2.0, 3.0)
|
|
scale = 1
|
|
focal_length = 1
|
|
|
|
# Act
|
|
result = project_perspective(point, scale=scale, focal_length=focal_length)
|
|
|
|
# Assert
|
|
assert math.isclose(result[0], 13.0 / 3.0, abs_tol=1e-9)
|
|
assert math.isclose(result[1], 14.0 / 3.0, abs_tol=1e-9)
|
|
|
|
|
|
def test_project_perspective_scale_100_focal_length_2() -> None:
|
|
"""Testet die perspektivische Projektion mit scale=100 und focal_length=2."""
|
|
# Arrange
|
|
point = (1.0, 2.0, 3.0)
|
|
scale = 100
|
|
focal_length = 2
|
|
|
|
# Act
|
|
result = project_perspective(point, scale=scale, focal_length=focal_length)
|
|
|
|
# Assert
|
|
assert math.isclose(result[0], 1400.0 / 3.0, abs_tol=1e-9)
|
|
assert math.isclose(result[1], 1600.0 / 3.0, abs_tol=1e-9)
|