59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
import pytest
|
|
import math
|
|
from src.browser.ghost_cursor import GhostCursorEngine
|
|
|
|
def test_bezier_curve_generation():
|
|
engine = GhostCursorEngine()
|
|
start = (0, 0)
|
|
end = (100, 100)
|
|
|
|
# Test control point generation
|
|
c1, c2 = engine._generate_bezier_controls(start, end)
|
|
|
|
# Basic bounds check: Control points should be somewhat between start and end
|
|
# but can overshoot.
|
|
# Just ensure they are tuples of floats
|
|
assert isinstance(c1, tuple)
|
|
assert len(c1) == 2
|
|
assert isinstance(c2, tuple)
|
|
assert len(c2) == 2
|
|
|
|
def test_bezier_point_calculation():
|
|
engine = GhostCursorEngine()
|
|
p0 = (0,0)
|
|
p1 = (10, 20)
|
|
p2 = (80, 90)
|
|
p3 = (100, 100)
|
|
|
|
# t=0 should be start
|
|
res_0 = engine._bezier_point(0, p0, p1, p2, p3)
|
|
assert math.isclose(res_0[0], 0)
|
|
assert math.isclose(res_0[1], 0)
|
|
|
|
# t=1 should be end
|
|
res_1 = engine._bezier_point(1, p0, p1, p2, p3)
|
|
assert math.isclose(res_1[0], 100)
|
|
assert math.isclose(res_1[1], 100)
|
|
|
|
# t=0.5 should be somewhere in between
|
|
res_mid = engine._bezier_point(0.5, p0, p1, p2, p3)
|
|
assert 0 < res_mid[0] < 100
|
|
assert 0 < res_mid[1] < 100
|
|
|
|
def test_waypoints_generation():
|
|
engine = GhostCursorEngine()
|
|
start = (0, 0)
|
|
end = (300, 300)
|
|
count = 3
|
|
|
|
waypoints = engine._generate_waypoints(start, end, count)
|
|
|
|
assert len(waypoints) == count + 1 # +1 for the end point
|
|
assert waypoints[0] == start
|
|
assert waypoints[-1] == end
|
|
|
|
# Check intermediate points exist
|
|
for i in range(1, count):
|
|
assert waypoints[i] != start
|
|
assert waypoints[i] != end
|
|
|