Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 List, Sequence, Tuple, Union

from rclpy.impl.rcutils_logger import RcutilsLogger
Expand Down Expand Up @@ -44,6 +45,13 @@ def __init__(
when building the neighbourhood list. Defaults to 0.15.
"""
super().__init__(logger)
if not obj_types:
raise ValueError("obj_types must be a non-empty list")
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.obj_types = obj_types
self.threshold_distance = threshold_distance

Expand Down
14 changes: 14 additions & 0 deletions tests/rai_bench/manipulation_o3de/tasks/test_group_objects_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,17 @@ def test_calculate_no_specified_objects() -> None:

assert correct == 0
assert misclustered == 0


import pytest


@pytest.mark.parametrize("bad", [0, -1.0, float("nan"), float("inf")])
def test_group_objects_rejects_bad_threshold(bad):
with pytest.raises(ValueError, match="threshold_distance"):
GroupObjectsTask(obj_types=["red_cube"], threshold_distance=bad)


def test_group_objects_rejects_empty_obj_types():
with pytest.raises(ValueError, match="obj_types"):
GroupObjectsTask(obj_types=[], threshold_distance=0.15)