diff --git a/src/rai_bench/rai_bench/manipulation_o3de/tasks/rotate_object_task.py b/src/rai_bench/rai_bench/manipulation_o3de/tasks/rotate_object_task.py index 893619f1e..802f8022e 100644 --- a/src/rai_bench/rai_bench/manipulation_o3de/tasks/rotate_object_task.py +++ b/src/rai_bench/rai_bench/manipulation_o3de/tasks/rotate_object_task.py @@ -14,6 +14,7 @@ import logging import math +import math from typing import List, Sequence, Tuple, Union from rai.types import Quaternion @@ -46,7 +47,22 @@ def __init__( The target rotation expressed as a quaternion (x, y, z, w). """ super().__init__(logger=logger) - self.obj_types = obj_types + if not obj_types: + raise ValueError("obj_types must be a non-empty list") + if not all(isinstance(x, str) and x.strip() for x in obj_types): + raise ValueError("obj_types must contain non-empty strings") + comps = ( + float(target_quaternion.x), + float(target_quaternion.y), + float(target_quaternion.z), + float(target_quaternion.w), + ) + if not all(math.isfinite(c) for c in comps): + raise ValueError("target_quaternion components must be finite") + norm = math.sqrt(sum(c * c for c in comps)) + if not math.isfinite(norm) or norm < 1e-6: + raise ValueError("target_quaternion must have non-zero norm") + self.obj_types = list(obj_types) self.target_quaternion = target_quaternion @property diff --git a/tests/rai_bench/manipulation_o3de/tasks/test_rotate_objects_task.py b/tests/rai_bench/manipulation_o3de/tasks/test_rotate_objects_task.py index b835e1b92..8c0cf8272 100644 --- a/tests/rai_bench/manipulation_o3de/tasks/test_rotate_objects_task.py +++ b/tests/rai_bench/manipulation_o3de/tasks/test_rotate_objects_task.py @@ -91,3 +91,23 @@ def test_calculate_error_above_threshold() -> None: # The rotation error is 10°, so it exceeds the 5° threshold. assert correct == 0 assert incorrect == 1 + +import pytest + + +def test_reject_empty_obj_types() -> None: + target = Quaternion(x=0.0, y=0.0, z=0.0, w=1.0) + with pytest.raises(ValueError): + RotateObjectTask([], target_quaternion=target) + + +def test_reject_non_finite_quaternion() -> None: + target = Quaternion(x=float("nan"), y=0.0, z=0.0, w=1.0) + with pytest.raises(ValueError): + RotateObjectTask(["apple"], target_quaternion=target) + + +def test_reject_zero_norm_quaternion() -> None: + target = Quaternion(x=0.0, y=0.0, z=0.0, w=0.0) + with pytest.raises(ValueError): + RotateObjectTask(["apple"], target_quaternion=target)