From 22757c3225db14811544b8cb0fb4054be8a4ddbc Mon Sep 17 00:00:00 2001 From: Bartok9 Date: Tue, 28 Jul 2026 01:52:56 -0400 Subject: [PATCH] fix(bench): reject non-positive PlaceCubesTask threshold_distance Signed-off-by: Bartok9 --- .../manipulation_o3de/tasks/place_cubes_task.py | 6 ++++++ .../manipulation_o3de/tasks/test_place_cubes_task.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/rai_bench/rai_bench/manipulation_o3de/tasks/place_cubes_task.py b/src/rai_bench/rai_bench/manipulation_o3de/tasks/place_cubes_task.py index 4337f7b19..36d9f4394 100644 --- a/src/rai_bench/rai_bench/manipulation_o3de/tasks/place_cubes_task.py +++ b/src/rai_bench/rai_bench/manipulation_o3de/tasks/place_cubes_task.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging +import math from typing import Sequence, Tuple, Union from rclpy.impl.rcutils_logger import RcutilsLogger @@ -43,6 +44,11 @@ def __init__( Defaults to 0.15. """ super().__init__(logger) + if not math.isfinite(threshold_distance) or threshold_distance <= 0: + raise ValueError( + "threshold_distance must be a finite number greater than 0, " + f"got {threshold_distance!r}" + ) self.threshold_distance = threshold_distance @property diff --git a/tests/rai_bench/manipulation_o3de/tasks/test_place_cubes_task.py b/tests/rai_bench/manipulation_o3de/tasks/test_place_cubes_task.py index 179666be5..54b755992 100644 --- a/tests/rai_bench/manipulation_o3de/tasks/test_place_cubes_task.py +++ b/tests/rai_bench/manipulation_o3de/tasks/test_place_cubes_task.py @@ -59,3 +59,15 @@ def test_calculate_2_clusters_adjacent() -> None: correct, incorrect = task.calculate_correct([e1, e2, e3, e4]) assert correct == 4 assert incorrect == 0 + +import math +import pytest + + +@pytest.mark.parametrize( + "bad", + [0, -0.1, float("nan"), float("inf"), float("-inf")], +) +def test_place_cubes_task_rejects_non_positive_threshold(bad): + with pytest.raises(ValueError, match="threshold_distance"): + PlaceCubesTask(threshold_distance=bad)