seventh commit: test2 added

This commit is contained in:
Tia Lechner committed 2026-11-03 12:08:42 +01:00
1 parent e6d4274525
commit fcf580f978
1 file changed
+43 -22
@@ -10,39 +10,60 @@ def approx_equal(a: float, b: float, rel_tol: float = 1e-9) -> bool:
@pytest.mark.parametrize(
"point,focal_length,scale,expected",
"point,focal_length,expected",
[
# Case 1 – no scaling, unit focal length
# Standardpunkt mit f = 1.0
(
(1.0, 2.0, 3.0),
1.0, # focal_length
1.0, # scale
(
1.0 / (4.0 + 3.0), # x projected
2.0 / (4.0 + 3.0), # y projected
),
1.0,
(1.0 / (4.0 + 3.0), 2.0 / (4.0 + 3.0)),
),
# Case 2 – scale 100, focal length 2
# Anderer Punkt und andere Brennweite
(
(1.0, 2.0, 3.0),
2.0, # focal_length
100.0, # scale
(
2.0 * 100.0 / (4.0 + 3.0), # x projected
2.0 * 100.0 * 2.0 / (4.0 + 3.0), # y projected
),
(2.0, -4.0, 1.0),
2.0,
(2.0 * 2.0 / (4.0 + 1.0), 2.0 * -4.0 / (4.0 + 1.0)),
),
],
)
def test_project_perspective(point, focal_length, scale, expected):
"""Test that project_perspective returns the correct 2‑D projection."""
# Call the function under test
result = project_perspective(point, focal_length=focal_length, scale=scale)
def test_project_perspective_points(point, focal_length, expected):
"""Testet die Perspektivenprojektion für verschiedene Punkte und Brennweiten."""
result = project_perspective(point, focal_length=focal_length, scale=1.0)
# Basic sanity checks
assert isinstance(result, tuple), "Result should be a tuple"
assert len(result) == 2, "Result should contain two coordinates"
assert approx_equal(result[0], expected[0]), f"X coordinate mismatch: {result[0]} != {expected[0]}"
assert approx_equal(result[1], expected[1]), f"Y coordinate mismatch: {result[1]} != {expected[1]}"
# Confirm values are close to expected (within tiny tolerance)
@pytest.mark.parametrize(
"scale,expected",
[
# Standard Skalierung (1.0)
(
1.0,
(2.0 * 1.0 / (4.0 + 3.0), 2.0 * 2.0 / (4.0 + 3.0)),
),
# Hohe Skalierung (100.0)
(
100.0,
(2.0 * 100.0 * 1.0 / (4.0 + 3.0), 2.0 * 100.0 * 2.0 / (4.0 + 3.0)),
),
# Kleine Skalierung (0.5)
(
0.5,
(2.0 * 0.5 * 1.0 / (4.0 + 3.0), 2.0 * 0.5 * 2.0 / (4.0 + 3.0)),
),
],
)
def test_project_perspective_scale(scale, expected):
"""Testet gezielt die Auswirkung verschiedener Skalierungsfaktoren (scale)."""
point = (1.0, 2.0, 3.0)
focal_length = 2.0
result = project_perspective(point, focal_length=focal_length, scale=scale)
assert isinstance(result, tuple), "Result should be a tuple"
assert len(result) == 2, "Result should contain two coordinates"
assert approx_equal(result[0], expected[0]), f"X coordinate mismatch: {result[0]} != {expected[0]}"
assert approx_equal(result[1], expected[1]), f"Y coordinate mismatch: {result[1]} != {expected[1]}"