Files
wehub-resource-sync 9194ef5abd
Docs/Test Workflow / Test docs build (push) Failing after 0s
Check links & references / links-check (push) Failing after 1s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.10) (push) Failing after 0s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.11) (push) Failing after 0s
PR Conflict Labeler / main (push) Failing after 2s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.12) (push) Failing after 2s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.13) (push) Failing after 0s
Pytest/Test Workflow / Build this Package (push) Failing after 5s
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.10) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.11) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.12) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.13) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.10) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.11) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.12) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.13) (push) Has been cancelled
Pytest/Test Workflow / testing-guardian (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:06:10 +08:00

79 lines
3.9 KiB
Python

import pytest
from supervision.geometry.core import Point, Position, Vector
def test_position_list_returns_enum_values_in_definition_order() -> None:
"""Position.list returns stable string values for public option lists."""
assert Position.list() == [position.value for position in Position]
@pytest.mark.parametrize(
("vector", "point", "expected_result"),
[
(Vector(start=Point(x=0, y=0), end=Point(x=5, y=5)), Point(x=-1, y=1), 10.0),
(Vector(start=Point(x=0, y=0), end=Point(x=5, y=5)), Point(x=6, y=6), 0.0),
(Vector(start=Point(x=0, y=0), end=Point(x=5, y=5)), Point(x=3, y=6), 15.0),
(Vector(start=Point(x=5, y=5), end=Point(x=0, y=0)), Point(x=-1, y=1), -10.0),
(Vector(start=Point(x=5, y=5), end=Point(x=0, y=0)), Point(x=6, y=6), 0.0),
(Vector(start=Point(x=5, y=5), end=Point(x=0, y=0)), Point(x=3, y=6), -15.0),
(Vector(start=Point(x=0, y=0), end=Point(x=1, y=0)), Point(x=0, y=0), 0.0),
(Vector(start=Point(x=0, y=0), end=Point(x=1, y=0)), Point(x=0, y=-1), -1.0),
(Vector(start=Point(x=0, y=0), end=Point(x=1, y=0)), Point(x=0, y=1), 1.0),
(Vector(start=Point(x=1, y=0), end=Point(x=0, y=0)), Point(x=0, y=0), 0.0),
(Vector(start=Point(x=1, y=0), end=Point(x=0, y=0)), Point(x=0, y=-1), 1.0),
(Vector(start=Point(x=1, y=0), end=Point(x=0, y=0)), Point(x=0, y=1), -1.0),
(Vector(start=Point(x=1, y=1), end=Point(x=1, y=3)), Point(x=0, y=0), 2.0),
(Vector(start=Point(x=1, y=1), end=Point(x=1, y=3)), Point(x=1, y=4), 0.0),
(Vector(start=Point(x=1, y=1), end=Point(x=1, y=3)), Point(x=2, y=4), -2.0),
(Vector(start=Point(x=1, y=3), end=Point(x=1, y=1)), Point(x=0, y=0), -2.0),
(Vector(start=Point(x=1, y=3), end=Point(x=1, y=1)), Point(x=1, y=4), 0.0),
(Vector(start=Point(x=1, y=3), end=Point(x=1, y=1)), Point(x=2, y=4), 2.0),
],
)
def test_vector_cross_product(
vector: Vector, point: Point, expected_result: float
) -> None:
"""
Verify that Vector.cross_product correctly calculates the scalar value.
Scenario: Computing the cross product between a vector and a point.
Expected: Correct scalar value is returned, which is used to determine which side
of a line a point lies on (essential for line crossing counting).
"""
result = vector.cross_product(point=point)
assert result == expected_result
@pytest.mark.parametrize(
("vector", "expected_result"),
[
(Vector(start=Point(x=0, y=0), end=Point(x=0, y=0)), 0.0),
(Vector(start=Point(x=1, y=0), end=Point(x=0, y=0)), 1.0),
(Vector(start=Point(x=0, y=1), end=Point(x=0, y=0)), 1.0),
(Vector(start=Point(x=0, y=0), end=Point(x=1, y=0)), 1.0),
(Vector(start=Point(x=0, y=0), end=Point(x=0, y=1)), 1.0),
(Vector(start=Point(x=-1, y=0), end=Point(x=0, y=0)), 1.0),
(Vector(start=Point(x=0, y=-1), end=Point(x=0, y=0)), 1.0),
(Vector(start=Point(x=0, y=0), end=Point(x=-1, y=0)), 1.0),
(Vector(start=Point(x=0, y=0), end=Point(x=0, y=-1)), 1.0),
(Vector(start=Point(x=0, y=0), end=Point(x=3, y=4)), 5.0),
(Vector(start=Point(x=0, y=0), end=Point(x=-3, y=4)), 5.0),
(Vector(start=Point(x=0, y=0), end=Point(x=3, y=-4)), 5.0),
(Vector(start=Point(x=0, y=0), end=Point(x=-3, y=-4)), 5.0),
(Vector(start=Point(x=0, y=0), end=Point(x=4, y=3)), 5.0),
(Vector(start=Point(x=3, y=4), end=Point(x=0, y=0)), 5.0),
(Vector(start=Point(x=4, y=3), end=Point(x=0, y=0)), 5.0),
],
)
def test_vector_magnitude(vector: Vector, expected_result: float) -> None:
"""
Verify that Vector.magnitude correctly calculates Euclidean distance.
Scenario: Calculating the magnitude (length) of a vector.
Expected: Correct Euclidean distance between start and end points is returned,
fundamental for various spatial calculations.
"""
result = vector.magnitude
assert result == expected_result