49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
|
|
import unittest
|
||
|
|
|
||
|
|
from cockpit_agent.common.enums import Interaction, SliderOrientation
|
||
|
|
from cockpit_agent.execution.mock_executor import MockExecutor
|
||
|
|
from cockpit_agent.grounding.adapter import GroundingResult
|
||
|
|
from cockpit_agent.grounding.schemas import ActionGroundingResult
|
||
|
|
from cockpit_agent.planning.schemas import ActionPlan
|
||
|
|
|
||
|
|
|
||
|
|
def grounding(
|
||
|
|
query: str,
|
||
|
|
bbox: tuple[int, int, int, int],
|
||
|
|
) -> GroundingResult:
|
||
|
|
x1, y1, x2, y2 = bbox
|
||
|
|
return GroundingResult(
|
||
|
|
semantic_query=query,
|
||
|
|
bbox_relative=(0, 0, 0, 0),
|
||
|
|
bbox_pixel=bbox,
|
||
|
|
center_pixel=(round((x1 + x2) / 2), round((y1 + y2) / 2)),
|
||
|
|
image_width=400,
|
||
|
|
image_height=200,
|
||
|
|
raw_output="model output",
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
class MockExecutorGeometryTest(unittest.TestCase):
|
||
|
|
def test_slider_uses_knob_center_and_track_target(self) -> None:
|
||
|
|
plan = ActionPlan(
|
||
|
|
interaction=Interaction.DRAG,
|
||
|
|
function="tailgate_max_opening",
|
||
|
|
target_value=80,
|
||
|
|
normalized_target=0.6,
|
||
|
|
orientation=SliderOrientation.HORIZONTAL,
|
||
|
|
)
|
||
|
|
action = MockExecutor._propose_drag(
|
||
|
|
plan,
|
||
|
|
ActionGroundingResult(
|
||
|
|
source="roi_action_grounding",
|
||
|
|
track=grounding("track", (100, 80, 300, 100)),
|
||
|
|
knob=grounding("knob", (270, 75, 290, 105)),
|
||
|
|
),
|
||
|
|
)
|
||
|
|
self.assertEqual(action.start_pixel, (280, 90))
|
||
|
|
self.assertEqual(action.end_pixel, (220, 90))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
unittest.main()
|