-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_at_position.py
More file actions
61 lines (48 loc) · 1.96 KB
/
Copy pathtest_at_position.py
File metadata and controls
61 lines (48 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import math
import pytest
def compute_at_position(
tool_x: float,
tool_y: float,
active_points: list,
selected_point: int,
tolerance: float,
) -> bool:
"""Reproduce the at_position logic from FloatView.update_tick()."""
if not active_points:
return False
if not (0 <= selected_point < len(active_points)):
return False
pt = active_points[selected_point]
dist = math.hypot(tool_x - pt[0], tool_y - pt[1])
return dist <= tolerance
class TestAtPosition:
def test_tool_exactly_on_point(self):
points = [(10.0, 20.0), (30.0, 40.0)]
assert compute_at_position(10.0, 20.0, points, 0, 0.05) is True
def test_tool_within_tolerance(self):
points = [(10.0, 20.0)]
assert compute_at_position(10.03, 20.04, points, 0, 0.05) is True
def test_tool_outside_tolerance(self):
points = [(10.0, 20.0)]
assert compute_at_position(10.1, 20.1, points, 0, 0.05) is False
def test_no_points(self):
assert compute_at_position(0.0, 0.0, [], 0, 0.05) is False
def test_invalid_selected_index(self):
points = [(1.0, 2.0)]
assert compute_at_position(1.0, 2.0, points, 5, 0.05) is False
def test_custom_tolerance_large(self):
points = [(0.0, 0.0)]
# Distance is ~1.414, within tolerance of 2.0
assert compute_at_position(1.0, 1.0, points, 0, 2.0) is True
def test_custom_tolerance_small(self):
points = [(0.0, 0.0)]
# Distance is 0.01, outside tolerance of 0.005
assert compute_at_position(0.01, 0.0, points, 0, 0.005) is False
def test_selected_second_point(self):
points = [(0.0, 0.0), (5.0, 5.0)]
# Far from first point but on second point
assert compute_at_position(5.0, 5.0, points, 1, 0.05) is True
def test_at_boundary(self):
points = [(0.0, 0.0)]
# Distance exactly equal to tolerance
assert compute_at_position(0.05, 0.0, points, 0, 0.05) is True